IPHONE - 以不同时间淡入和淡出 UIImageView

Posted

技术标签:

【中文标题】IPHONE - 以不同时间淡入和淡出 UIImageView【英文标题】:IPHONE - fade in and fade out of a UIImageView with different times 【发布时间】: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 或其他方法有关吗? 怎么可能?

感谢您的帮助!

【问题讨论】:

【参考方案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];

【讨论】:

谢谢,但我已经尝试过了,动画在第一部分和第二部分之间冻结了一毫秒。它需要是连续的。

以上是关于IPHONE - 以不同时间淡入和淡出 UIImageView的主要内容,如果未能解决你的问题,请参考以下文章

Swift Infinite淡入和淡出循环

复制 iBooks 缩放/淡入淡出动画

如何添加淡入淡出功能以在悬停功能上播放?

动画 UIButton 状态以在点击时淡入和淡出

MPMoviePlayerController 添加 UIButton 以查看淡入淡出的控件

JQuery:结合动画 CSS 和淡入淡出