0

我需要使用 UIViewAnimationOptionTransitionCurlUp 动画重新加载(更新)self.view。在视觉上,旧视图以卷曲效果进行动画处理,并且在其后呈现新的更新视图。我找不到比创建当前视图的屏幕截图更好的方法,将其放在最上面,然后应用动画将其卷起并删除。然后在旧视图卷起后,更新的视图元素会很好地呈现。

但是,卷曲不起作用。过渡变得淡出而不是卷曲。怎么了?代码如下。

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];
                }];
4

2 回答 2

1

这是正确的版本:

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

transitionWithView 是 self.view 和动画块应该删除screenView

于 2013-02-26T16:04:30.550 回答
0

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

尝试在动画块中添加子视图(并且仅在此处)以使视图添加动画:

[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];
于 2013-02-26T15:32:11.977 回答