根据Apples文档(以及许多其他地方),如果UIScrollView.pagingEnabled设置为YES,则UIScrollViewDelegate:scrollViewWillEndDragging:withVelocity:targetContentOffset不会被调用。在iOS6上,这似乎是真的,但是,在iOS7上,无论设置什么是pagingEnabled,它总是被我调用。
这是一个简单的测试视图控制器:
@interface ViewController ()
<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end
@implementation ViewController
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
NSLog(@"%d", scrollView.pagingEnabled);
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadHTML];
[self configureWebView];
}
- (void)loadHTML
{
NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"htmlContent" ofType:@"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
[_webView loadHTMLString:htmlString baseURL:nil];
}
- (void)configureWebView
{
[_webView.scrollView setDelegate:self];
_webView.scrollView.pagingEnabled = YES;
}
@end
在iOS7中,如果pagingEnabled == YES,则scrollViewWillEndDragging中的NSLog打印1,如果设置为NO,则打印0。
在iOS6中,当pagingEnabled == YES时,控制台输出为:
Stop offset can not be modified for paging scroll views
如果为NO,则输出为0.
还有其他人得到这个吗?有谁知道在iOS7中这应该是这样吗?文档没有改变,所以我假设没有,但我想在向Apple提交错误报告并在我的所有委托调用中添加对pagingEnabled的检查之前,我会问你们所有人。