【问题标题】:IPHONE - fade in and fade out of a UIImageView with different timesIPHONE - 以不同时间淡入和淡出 UIImageView
【发布时间】:2010-02-17 23:08:43
【问题描述】:

我想使用不同的时间淡入和淡出 UIImageView,比如说,使用以下参数:

  • t = 0 ... UIImageView 的 alpha = 0
  • t = 0.5s ... UIImageView 的 alpha = 0.7
  • t = 0.7s ... UIImageView 的 alpha = 0

这可能与 CAAnimation 或其他方法有关吗? 怎么可能?

感谢您的帮助!

【问题讨论】:

    标签: iphone iphone-sdk-3.0 ipad


    【解决方案1】:
    if (imgDefault.alpha == 0.0) {
        CGContextRef context = UIGraphicsGetCurrentContext();
            [UIView beginAnimations:nil context:context];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
            [UIView setAnimationDuration: 3.0];
            [UIView setAnimationDelegate: self];
            imgDefault.alpha = 1.0;
            [UIView commitAnimations];
    }
    else {
        CGContextRef context = UIGraphicsGetCurrentContext();
            [UIView beginAnimations:nil context:context];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
            [UIView setAnimationDuration: 3.0];
            [UIView setAnimationDelegate: self];
            imgDefault.alpha = 0.0;
            [UIView commitAnimations];
    }
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      您可能应该研究一下 CAKeyframeAnimation。它可以让您设置多个时间点的值。

      【讨论】:

        【解决方案3】:

        UIView 有一个你可以使用的 setAnimationDidStopSelector: 方法。只需使用 beginAnimations 块设置淡入动画,并将 didStop 选择器设置为仅包含淡出动画块的另一个方法。这些动画块中的每一个都可以有不同的动画持续时间。

        类似这样的:

            [UIView beginAnimations:next context:context];
            [UIView setAnimationDuration:0.5];
            [UIView setAnimationDelegate:self];
            [UIView setAnimationDidStopSelector:@selector(fadeOut:finished:context:)];
            myView.alpha = 0.7;
            [UIView commitAnimations];
        
        -(void)fadeOut:(NSString*)animationID finished:(BOOL)finished context:(void*)context  {
            [UIView beginAnimations:nil context:context];
            [UIView setAnimationDuration:0.2];
            myView.alpha = 0.0;
            [UIView commitAnimations];
        }
        

        【讨论】:

        • 谢谢,但我已经尝试过了,动画在第一部分和第二部分之间冻结了一毫秒。它需要是连续的。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-07-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-11
        • 1970-01-01
        相关资源
        最近更新 更多