【问题标题】:UIView Animation at viewDidLoad/viewDidAppear?viewDidLoad/viewDidAppear 的 UIView 动画?
【发布时间】:2013-10-25 23:25:26
【问题描述】:

我正在 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 方法实现?你会如何解决这个问题?

谢谢。

【问题讨论】:

  • 您为什么要在viewDidLoad 中这样做?该视图尚未显示。在viewDidAppear:viewWillAppear: 中制作动画。
  • 我在viewDidAppear试过,效果一样。

标签: ios objective-c animation uiview


【解决方案1】:

您需要淡入屏幕截图。如果您使用两个图像,则需要将一个图像视图放在另一个之上。 pop this inside viewDidAppear: after calling [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];
}];

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 对我来说解决了,关键是 viewDidLoad 没有动画。
    【解决方案3】:

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

    self.layoutIfNeeded()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多