作为动画的一部分,我有一个视图,我想更深入地进入视图层次结构。 (我之前将它移动到视图层次结构的顶部,以便执行显示在其他UI元素之上的动画。)我正在使用此代码,它执行正确的操作。
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 :(得分:0)
尝试
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];
或
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;
}];
答案 1 :(得分:0)
我在没有闪烁的情况下使用了这个:
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];
}];
答案 2 :(得分:0)
在我的情况下,问题是addSubview是在后台线程中执行的。 您需要在主队列上执行更改,它应该可以正常工作。
尝试
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;
}