【发布时间】:2017-04-04 13:02:49
【问题描述】:
当我点击 ScrollView 时,它会调用方法 scrollViewWillBeginDecelerating 和 scrollViewDidEndDecelerating,即使在将 scrollView's 设置为 pagingEnabled 到 YES 之后也是如此
我有scrollView 和subViews 并尝试根据subViews 设置contentOffset。但它不起作用。
这是我的代码:
self.myScrollView.frame = CGRectMake(0, 0, pageWidth, pageHeight);
self.myScrollView.contentSize = CGSizeMake(pageWidth * self.contentViewControllers.count, pageHeight);
for (NSInteger i = 0; i < self.contentViewControllers.count; i++) {
UILabel *label = [UILabel new];
label.textColor = [UIColor whiteColor];
label.textAlignment = NSTextAlignmentCenter;
label.text = [NSString stringWithFormat:@"Page %ld",i];
label.backgroundColor = [UIColor randomColor];
label.frame = CGRectMake(i * pageWidth, 0, pageWidth, pageHeight);
[self.myScrollView addSubview:label];
}
self.myScrollView.contentInset = UIEdgeInsetsMake(120, 0, 0, 0);
self.myScrollView.contentOffset = CGPointMake(0, - 120);
self.myScrollView.scrollIndicatorInsets = UIEdgeInsetsMake(120, 0, 0, 0);
- (UIScrollView *)myScrollView{
if (!_myScrollView) {
_myScrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
_myScrollView.backgroundColor = [UIColor blackColor];
_myScrollView.pagingEnabled = YES;
_myScrollView.directionalLockEnabled = YES;
_myScrollView.delegate = self;
//_myScrollView.delaysContentTouches = NO;
//_myScrollView.scrollsToTop = NO;
}
return _myScrollView;
}
当我点击scrollView 中的任何subView 时,它会调用委托方法:
scrollViewWillBeginDecelerating >> scrollViewDidScroll >> scrollViewDidEndDecelerating
而contentOffset 更改为{0,0}
【问题讨论】:
标签: ios objective-c uiscrollview uiscrollviewdelegate