0
ウェブビューがバウンスするのを止めようとしているときに、ユーザーがアプリ/スクリーンをドラッグしたときに上に空白が表示されます。Webビューのバウンスを停止するとエラーが表示されます
#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
メッセージを持つ:これは動作しないコードであるomcompatibleタイプから 'ID _Nullable' に割り当て 'のWebView * constの__strong'
私は' @interface ViewControllerを置くべきか? –
'UIScrollViewDelegate'を採用している限り、上手くいくはずです。それでもエラーが発生した場合は、クラスにアクセスできるブレークポイントを設定し、 'po [var_name class]'を使用してクラス・クラスをコンソールに表示します。 – Sheamus