Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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 UIScrollView-setContentOffset:动画“是”或“否”会产生不同的结果_Ios_Objective C_Uiscrollview - Fatal编程技术网

Ios UIScrollView-setContentOffset:动画“是”或“否”会产生不同的结果

Ios UIScrollView-setContentOffset:动画“是”或“否”会产生不同的结果,ios,objective-c,uiscrollview,Ios,Objective C,Uiscrollview,嘿嘿,, 我知道这听起来很愚蠢。我正在编写我的第一个UIScrollView,并试图根据一些参数设置滚动视图中元素的位置。我发现我可以使用setContentOffset来实现这一点,但无论我向该函数输入什么值,结果总是一样的,我不知道为什么?(滚动视图的内容大小是否有问题?) 这是我的密码: 首先,我设置了如下滚动视图: //make view scrollable scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, [

嘿嘿,, 我知道这听起来很愚蠢。我正在编写我的第一个UIScrollView,并试图根据一些参数设置滚动视图中元素的位置。我发现我可以使用setContentOffset来实现这一点,但无论我向该函数输入什么值,结果总是一样的,我不知道为什么?(滚动视图的内容大小是否有问题?)

这是我的密码:

首先,我设置了如下滚动视图:

//make view scrollable
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-216-30)];
scrollView.scrollsToTop = NO;
scrollView.bounces=NO;
[self.view addSubview: scrollView];
scrollView.contentSize=CGSizeMake([[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-110);
然后我尝试设置滚动视图的位置

 if(yMultiplier==4){
                [scrollView setContentOffset:CGPointMake(0,imageHeight) animated:NO];
                NSLog(@"4");
            } else
    if(yMultiplier==5){
                [scrollView setContentOffset:CGPointMake(0,imageHeight*2) animated:NO];
                NSLog(@"4");
            }
编辑: 无论CGPoint的y坐标是什么,它总是滚动到完全相同的点。 我现在尝试使用动画:是的。这会导致一些不同的结果。然后它滚动到预定的位置,但我有一个新的问题:因为我根据用户类型添加了几个图像,所以滚动可以很好地用于其他图像。对于第二个图像,它会滚动回原始位置。。。 这就是代码

if(yMultiplier>3){
            CGPoint bottomOffset = CGPointMake(0, imageHeight*3);
            [scrollView setContentOffset:bottomOffset animated:YES];
        }
编辑: 在
-(void)scrollViewDidScroll:(UIScrollView*)scrollView中记录偏移量{
NSLog(@“偏移量:%f,%f”,scrollView.contentOffset.x,scrollView.contentOffset.y);
}
给出了:

最初:

offset: 0.000000, -64.000000
offset: 0.000000, -64.000000
进入正确位置时:

2014-06-26 16:56:28.722 ualphabets[5058:60b] offset: 0.000000, -63.500000
2014-06-26 16:56:28.739 ualphabets[5058:60b] offset: 0.000000, -61.500000
2014-06-26 16:56:28.756 ualphabets[5058:60b] offset: 0.000000, -57.500000
2014-06-26 16:56:28.772 ualphabets[5058:60b] offset: 0.000000, -51.500000
2014-06-26 16:56:28.789 ualphabets[5058:60b] offset: 0.000000, -44.000000
2014-06-26 16:56:28.806 ualphabets[5058:60b] offset: 0.000000, -35.000000
2014-06-26 16:56:28.822 ualphabets[5058:60b] offset: 0.000000, -25.500000
2014-06-26 16:56:28.839 ualphabets[5058:60b] offset: 0.000000, -14.500000
2014-06-26 16:56:28.855 ualphabets[5058:60b] offset: 0.000000, -3.500000
2014-06-26 16:56:28.872 ualphabets[5058:60b] offset: 0.000000, 7.500000
2014-06-26 16:56:28.889 ualphabets[5058:60b] offset: 0.000000, 18.500000
2014-06-26 16:56:28.905 ualphabets[5058:60b] offset: 0.000000, 29.000000
2014-06-26 16:56:28.922 ualphabets[5058:60b] offset: 0.000000, 39.000000
2014-06-26 16:56:28.939 ualphabets[5058:60b] offset: 0.000000, 47.000000
2014-06-26 16:56:28.956 ualphabets[5058:60b] offset: 0.000000, 54.000000
2014-06-26 16:56:28.972 ualphabets[5058:60b] offset: 0.000000, 59.500000
2014-06-26 16:56:28.989 ualphabets[5058:60b] offset: 0.000000, 63.500000
2014-06-26 16:56:29.005 ualphabets[5058:60b] offset: 0.000000, 65.000000
每隔一段时间,图像就会跳转到错误的地方:

2014-06-26 16:56:31.516 ualphabets[5058:60b] offset: 0.000000, 12.500000

请记录
contentsize
imageheight
?在上面的编辑中解释了结果。内容大小:320.000000,458.000000图像高度65.099998能否记录
scrollViewDidScroll:
方法以查看偏移量是如何变化的?设置
动画:是
偏移量不变。它始终保持在imageHeight或imageHeight*2