繁体   English   中英

在viewDidLoad / viewDidAppear的UIView动画?

[英]UIView Animation at viewDidLoad/viewDidAppear?

我正在viewDidLoad或viewDidAppear方法中尝试一个简单的UIView动画,但它没有动画。

UIImage *bluredScreenshot = [self.parentViewControllerScreenshot applyBlur];

    [UIView transitionWithView:self.screenshotView duration:3.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        self.screenshotView.image = bluredScreenshot;
    } completion:nil];

简单的交叉溶解两个图像。 从viewDidLoad或viewDidAppear运行时,图像会更改但不会设置动画。

但是让我说我​​按下一个按钮后从一个方法运行动画,它会动画。 为什么? 似乎很奇怪。

是否可以从viewDidLoad方法中创建它? 你怎么解决这个问题?

谢谢。

当视图加载时,您无法设置动画,因为没有任何动画效果。 尝试在viewdidapear:并且不要使用过渡

[UIView animateWithDuration:3.
                      delay:0
                    options:UIViewAnimationOptionTransitionCrossDissolve
                 animations:^{
                             self.screenshotView.image = bluredScreenshot;
                 }
                 completion:nil];

你需要淡入屏幕截图。 如果您使用的是两张图像,则需要将一张图像视图放在另一张图像上。 在viewDidAppear内部弹出:调用[super viewDidAppear:animated];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.screenshotView.frame];
[self.view addSubview:imageView];
    [imageView setAlpha:0.0f];
    imageView = blurredScreenshot;
    [UIView animateWithDuration:0.3f animations:^{
                [imageView setAlpha:1.0f];
            } completion:^(BOOL finished){
                self.imageView.image = blurredScreenshot;
                [imageView removeFromSuperview];
}];

只是提醒一下,有时你的问题可能是由于没有打电话引起的:

self.layoutIfNeeded()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM