0
嘗試阻止網頁瀏覽反彈,當用戶拖動應用程序/屏幕時,頂部會出現一個空白區域。這是不正常的代碼:停止網頁瀏覽反彈顯示錯誤
#import "Webview.h"
@interface Webview()
@end
@implementation Webview
@synthesize webView;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString *urlAddress= [[NSBundle mainBundle] pathForResource:@"demos/index" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath: urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
webView.scrollView.delegate = self;
webView.scrollView.bounces = NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//The webview is is scrolling
int yPosition = [[webView stringByEvaluatingJavaScriptFromString: @"scrollY"] intValue];
if([[webView stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"] intValue] - yPosition == webView.frame.size.height)
{
//The user scrolled to the bottom of the webview
webView.scrollView.bounces = YES;
}else if([[webView stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"] intValue] - yPosition > webView.frame.size.height + 100){
webView.scrollView.bounces = NO;
}
}
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{
NSLog(@"Finish");
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
有消息:分配到「身份證_Nullable」從omcompatible型「web視圖* const的__strong」
我應該把'@interface的ViewController:UIViewController中'代替'@interface網頁視圖()'? –
只要你採用'UIScrollViewDelegate',你應該沒問題。如果你仍然得到這個錯誤,那麼在你可以訪問該類的地方設置一個斷點,並在控制檯中打印出類的類,使用'po [var_name class]' – Sheamus