【问题标题】:Is there something wrong with my CAAnimation?我的 CAAnimation 有问题吗?
【发布时间】:2011-08-10 13:04:41
【问题描述】:

代码:

UIView *superView = [self.view superview];
CATransition *animation = [CATransition animation];
animation.duration = 0.5f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.type = kCATransitionFade;
animation.subtype = kCATransitionFromTop;
[root.view removeFromSuperview];
[self.view removeFromSuperview];
[superView.layer addAnimation:animation forKey:@"removeContentAnimation"];

self.view 和 root.view 被添加到“superView”中

当我提交这个动画时,有一点机会发生错误 - 两个视图都从 superView 中删除并立即返回。快速更改后,它正常消失了。

【问题讨论】:

  • 问题不是很清楚,错误是什么? self.view 和 root.view 是什么?

标签: iphone objective-c animation


【解决方案1】:

查看这个独库:http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html#//apple_ref/doc/uid/TP40009503-CH6-SW1

  1. 您不能为 removeFromSuperView 设置动画。
  2. 您应该使用块来为视图设置动画

这里有一个简短的提示:

- (IBAction)hideView:(id)sender
{
    [UIView animateWithDuration:1.0
        delay: 0.0
        options: UIViewAnimationOptionCurveEaseIn
        animations:^{
             viewToHide.alpha = 0.0;
        }
        completion:^(BOOL finished){
            [viewToHide removeFromSuperView];
        }];
}

【讨论】:

    猜你喜欢
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多