开发者

How to force screen update for UIScrollView from non-UI thread/function (iPhone)

开发者 https://www.devze.com 2022-12-16 10:47 出处:网络
I am drawing a set of images on the uiscrollv开发者_如何学Goiew from a non-ui thread/function. But its only displayed after all the images are done drawing. For drawing all the images, I have written

I am drawing a set of images on the uiscrollv开发者_如何学Goiew from a non-ui thread/function. But its only displayed after all the images are done drawing. For drawing all the images, I have written a function and that is what is being called as the non-ui thread. I did write this line inside the function

[self performSelectorOnMainThread:@selector(updateUI) withObject:nil waitUntilDone:NO];

And have written the function as given below

- (void)updateUI
{
[myScrollView setNeedsDisplay];
}

But its having no effect even when I can see the control being passed to that function. What to do now?


In my experience all drawing operations must be performed on the UI thread, even if they are not visible, or even added to the view hierarchy, when you are doing them. If you find a way around that I'd be keen to know, though :-)


Ok, I got a solution. Its working perfectly even though I dont like the solution. I changed my function like this.

- (void)updateUI
{
 for(UIView *subview in [myScrollView subviews]) 
 {
  [myScrollView bringSubviewToFront:subview];   
 } 
}


Maybe you should also call setNeedsLayout and/or layoutIfNeeded?


Try something like performSelectorOnMainThread:withObject:waitUntilDone:

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号