Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.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
Iphone 如何在向UIScrollView添加imageView之间显示UIScrollView?_Iphone_Uiscrollview_Uiimageview - Fatal编程技术网

Iphone 如何在向UIScrollView添加imageView之间显示UIScrollView?

Iphone 如何在向UIScrollView添加imageView之间显示UIScrollView?,iphone,uiscrollview,uiimageview,Iphone,Uiscrollview,Uiimageview,我有一个UIScrollView,我使用下面的代码向它添加了9个imageview for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"some url"]];

我有一个UIScrollView,我使用下面的代码向它添加了9个imageview

    for (i = 0; i < 3; i++)
       {
        for (j = 0; j < 3; j++)
        {
        imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"some url"]];
        frame = [imageView frame];
        frame.origin.x = x;
        frame.origin.y = y;
        [imageView setFrame:frame];
        imageView.userInteractionEnabled = YES;
        imageView.multipleTouchEnabled = YES;
        [myScrollView addSubview:imageView];
        }
       }
(i=0;i<3;i++)的

{
对于(j=0;j<3;j++)
{
imageView=[[UIImageView alloc]initWithImage:[UIImageName:[NSString stringWithFormat:@“某些url]”;
帧=[imageView帧];
frame.origin.x=x;
frame.origin.y=y;
[图像视图设置帧:帧];
imageView.userInteractionEnabled=是;
imageView.MultipleToTouchEnabled=是;
[myScrollView添加子视图:imageView];
}
}
我以为会显示UIScrollView,然后我们会看到每个图像都加载到平铺中。但只有在加载所有图像后,才会出现UIScrollView和所有图像。
如何让UIScrollView先显示,然后显示每个正在加载的图像?

在执行整个代码块之前,您正在阻止运行循环。因此,您的应用程序没有机会更新其绘图。您需要进行绘图(更具体地说,是下载图像)异步。下载图像后,您可以将其添加到UIScrollView。请注意,您希望在主线程上使用类似于
performSelectorOnMainThread…

的方法进行此绘制,但该方法工作正常,但半完美。问题是,即使加载了图像,如果我在scrollvi上执行任何当前操作ew则只有它能按我的要求工作,即用新图像替换当前图像,否则它会像前面的情况一样出现。但如果我只是玩它,我就能看到每个图像加载并替换以前的图像。当我什么都不做时,如何使其可见?不看代码就很难说。你可能没有o让runloop知道您的视图需要使用setNeedsDisplayInRect:方法更新其图形。