Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当ScrollView设置为PaginEnabled为YES时,点击ScrollView调用“ScrollView将开始加速”_Ios_Objective C_Uiscrollview_Uiscrollviewdelegate - Fatal编程技术网

Ios 当ScrollView设置为PaginEnabled为YES时,点击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时,它调用方法
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