Ios 当ScrollView设置为PaginEnabled为YES时,点击ScrollView调用“ScrollView将开始加速”
当我点击ScrollView时,它调用方法Ios 当ScrollView设置为PaginEnabled为YES时,点击ScrollView调用“ScrollView将开始加速”,ios,objective-c,uiscrollview,uiscrollviewdelegate,Ios,Objective C,Uiscrollview,Uiscrollviewdelegate,当我点击ScrollView时,它调用方法ScrollView将开始加速和ScrollViewDiEndDeceling,即使在ScrollView的设置为PaginEnabled后也是如此 我有滚动视图和子视图,并试图根据子视图设置contentOffset。但它不起作用 这是我的密码: self.myScrollView.frame = CGRectMake(0, 0, pageWidth, pageHeight); self.myScrollView.contentSize = CGSiz
ScrollView将开始加速
和ScrollViewDiEndDeceling
,即使在ScrollView的
设置为PaginEnabled
后也是如此
我有滚动视图
和子视图
,并试图根据子视图
设置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;
}
self.myScrollView.frame=CGRectMake(0,0,pageWidth,pageHeight);
self.myScrollView.contentSize=CGSizeMake(pageWidth*self.contentViewControllers.count,pageHeight);
对于(NSInteger i=0;i
当我点击滚动视图
中的任何子视图
时,它调用委托方法:
scrollViewWillBeginDecelerating
>scrollViewDidScroll
>scrollViewDidEndDecelerating
而
contentOffset
更改为{0,0}
请按如下方式更新您的代码:
请在for循环之后设置contentSize
self.myScrollView.frame = CGRectMake(0, 0, pageWidth, 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);
self.myScrollView.contentSize = CGSizeMake(pageWidth * self.contentViewControllers.count, pageHeight);
- (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;
}
self.myScrollView.frame=CGRectMake(0,0,pageWidth,pageHeight);
对于(NSInteger i=0;i