Move view to new flicker-free supervisor

As part of the animation, I have an idea that I want to delve into the hierarchy of representations. (I previously moved it to the top of the view hierarchy to perform an animation that appears on top of other user interface elements.) I use this code, which does the right thing.

CGRect rect = self.profileImage.frame; UIView *sv = self.profileImage.superview; [self.scrollview addSubview:self.profileImage]; rect = [self.scrollview convertRect:rect fromView:sv]; self.profileImage.frame = rect; 

However, when I do this, the view flickers. Any ideas how to avoid flickering?

+4
source share
3 answers

try

 CGRect rect = self.profileImage.frame; UIView *sv = self.profileImage.superview; rect = [self.scrollview convertRect:rect fromView:sv]; self.profileImage.frame = rect; [self.scrollview addSubview:self.profileImage]; 

or

 CGRect rect = self.profileImage.frame; UIView *sv = self.profileImage.superview; self.profileImage.alpha = 0.0f; rect = [self.scrollview convertRect:rect fromView:sv]; self.profileImage.frame = rect; [self.scrollview addSubview:self.profileImage]; [UIView animateWithDuration:0.0f animations:^{ self.profileImage.alpha = 1.0f; }]; 
0
source

I got this work flicker-free using:

 CGRect rect = self.profileImage.frame; UIView *sv = self.profileImage.superview; CGRect convertedRect = [self.scrollview convertRect:rect fromView:sv]; [UIView animateWithDuration:0.0 animations:^(void){ [self.profileImage setAlpha:0.0]; [self.profileImage setFrame:convertFrame]; [self.scrollview addSubview:self.profileImage]; [self.profileImage setAlpha:1.0]; }]; 
0
source

In my case, the problem was that addSubview was running in the background thread. You need to make the change in the main queue, and it should work fine.

try

 dispatch_async(dispatch_get_main_queue(), ^{ CGRect rect = self.profileImage.frame; UIView *sv = self.profileImage.superview; [self.scrollview addSubview:self.profileImage]; rect = [self.scrollview convertRect:rect fromView:sv]; self.profileImage.frame = rect; } 
0
source

Source: https://habr.com/ru/post/1335589/


All Articles