Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.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/8/xcode/7.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
scrollview在iPhone中无法正常工作_Iphone_Xcode - Fatal编程技术网

scrollview在iPhone中无法正常工作

scrollview在iPhone中无法正常工作,iphone,xcode,Iphone,Xcode,我是iOS编程新手,我的滚动视图不是水平滚动的 我想让它能够水平滚动,垂直它工作正常,但水平它不工作,请帮助我。我使用了以下代码 scrollView.frame = CGRectMake(0, 0, 600, 460); [scrollView setContentSize:CGSizeMake(320, 678)]; 尝试以下方法。这是我的工作代码。我正在水平滚动视图中添加图像 int scrollWidth=60; for (int i=0;i<

我是iOS编程新手,我的滚动视图不是水平滚动的

我想让它能够水平滚动,垂直它工作正常,但水平它不工作,请帮助我。我使用了以下代码

 scrollView.frame = CGRectMake(0, 0, 600, 460);
 [scrollView setContentSize:CGSizeMake(320, 678)];

尝试以下方法。这是我的工作代码。我正在水平滚动视图中添加图像

        int scrollWidth=60;
        for (int i=0;i<array.count;i++)
        {
            UIImageView *imageView1=[[UIImageView alloc]initWithFrame:CGRectMake(scrollWidth,8,50,40)];
            imageView1.userInteractionEnabled=YES;
            imageView1.backgroundColor=[array objectAtIndex:i];
            [scrollView addSubview:imageView1];
            scrollWidth=scrollWidth+80;
        }

        [scrollView setContentSize:CGSizeMake(scrollWidth, 30)];
int scrollWidth=60;

对于(int i=0;i您可以将scrollview的框架设置为CGRectMake(0,0320460),内容大小设置为[scrollview setContentSize:CGSizeMake(600678)];因为当滚动内容大小大于滚动视图的帧大小时会启用滚动,所以您可以设置宽度600,但内容大小为320,因此在这种情况下无法水平滚动。因此,您需要设置内容的宽度

 [scrollView setContentSize:CGSizeMake(600, 678)];
//use
scrollView.frame = CGRectMake(0, 0, 320, 460);
scrollView.contentSize = CGSizeMake(600,678);