重载UIView与UIViewAnimationOptionTransitionCurlUp动画



我需要重新加载(更新)self。视图与UIViewAnimationOptionTransitionCurlUp动画。视觉上,旧视图以卷动效果动画,更新后的新视图呈现。我找不到比创建当前视图的截图更好的方法,将其放在所有视图的顶部,并应用动画将其卷起和删除。在旧视图卷起后,更新后的视图元素会很好地呈现。

但是,卷起不起作用。过渡变成了渐变而不是卷曲。怎么了?代码如下:

UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIView* screenView = [[UIView alloc] initWithFrame:self.view.frame];
screenView.tag = TAG_SCREENSHOT_VIEW;
screenView.backgroundColor = [UIColor colorWithPatternImage:screenshot];
[self.view addSubview:screenView];
[screenView.superview bringSubviewToFront:screenView];
[UIView transitionWithView:screenView
                  duration:1.0f
                   options:UIViewAnimationOptionTransitionCurlUp
                animations:^ { screenView.alpha = 0.0f; }
                completion:^ (BOOL finished) {
                    [screenView removeFromSuperview];
                }];

正确的版本:

[UIView transitionWithView:self.view
                  duration:0.5f
                   options:UIViewAnimationOptionTransitionCurlUp
                animations:^ { [screenView removeFromSuperview]; }
                completion:nil];

transitionWithView是self。view和animation block应该移除screenView

实际上是通过在动画中将其alpha归零来淡出视图。

尝试在动画块中添加子视图(并且只在那里)以获得添加animated:

的视图
[UIView transitionWithView:self.view
              duration:1.0f
               options:UIViewAnimationOptionTransitionCurlUp
            animations:^ { [self.view addSubview:screenView]; screenView.alpha = 0.0f; }
            completion:^ (BOOL finished) {
                [screenView removeFromSuperview];
            }];

在任何情况下,我不确定我能理解screenView.alpha = 0.0f;在那里做什么。可能以下是更接近你想要实现的(在这种情况下,你需要在做动画之前添加子视图):

[UIView transitionWithView:self.view
              duration:1.0f
               options:UIViewAnimationOptionTransitionCurlUp
            animations:^ { [screenView removeFromSuperview]; }
            completion:nil];

最新更新