我有两个UIImageView - leftSide
和rightSide
,我希望淡入其中,然后逐个淡出,循环播放。
我如何在Xcode中执行此操作?我试过了CABasicAnimation
,但这不起作用(我不确定为什么,根本没有错误,图片也不会褪色)。
谢谢!
编辑:这是我正在使用的代码:
-(void)leftSideFade{
CABasicAnimation *blink;
blink = [CABasicAnimation animationWithKeyPath:@"opacity"];
blink.duration = 1.0;
blink.repeatCount = 5;
blink.autoreverses = YES;
blink.fromValue = [NSNumber numberWithFloat:1.0];
blink.toValue = [NSNumber numberWithFloat:0.0];
[leftSideStart.layer addAnimation:blink forKey:@"animateOpacity"];
[self rightSideFade];
}
-(void)rightSideFade{
CABasicAnimation *blink;
blink = [CABasicAnimation animationWithKeyPath:@"opacity"];
blink.duration = 1.0;
blink.repeatCount = 5;
blink.autoreverses = YES;
blink.fromValue = [NSNumber numberWithFloat:1.0];
blink.toValue = [NSNumber numberWithFloat:0.0];
[rightSideStart.layer addAnimation:blink forKey:@"animateOpacity"];
[self leftSideFade];
}
答案 0 :(得分:0)
- (void)fadeIn
{
[UIView beginAnimations:@"fadeIn Animation" context:nil];
[UIView setAnimationDuration:1.0];
imageView.alpha = 1.0;
[UIView commitAnimations];
}
试试这个。
答案 1 :(得分:0)
使用UIView animateWithDuration更简单的方法:动画:完成:? 在那里你只需改变你的观点的alpha,它们就会淡入/淡出 以下是示例代码:
[UIView animateWithDuration:duration
animations:^
{
//Here you set values you want to see in the end of animation
leftView.alpha = 0.0f;
rightView.alpha = 1.0f;
}
completion:^(BOOL finished)
{
//something to do after animation finished
}
答案 2 :(得分:0)
尝试使用以下内容:
- (void) fadeinRightFadwOutLeft {
[UIView beginAnimations:@"start" context:nil];
[UIView setAnimationDuration:1.0];
rightSide.alpha = 0.0;
leftSide.alpha = 1.0;
[UIView commitAnimations];
}
- (void) fadeinLeftFadwOutRight {
[UIView beginAnimations:@"start" context:nil];
[UIView setAnimationDuration:1.0];
leftSide.alpha = 0.0;
rightSide.alpha = 1.0;
[UIView commitAnimations];
}