我想创建一个改变 alpha 值的简单动画:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[view1 setAlpha:0.00];
[UIView commitAnimations];
好的,我用这种方式改变了 alpha 值两秒钟,效果很好,但我想要这样的东西: 当 alpha 为 0 时,动画必须再次开始到 alpha = 1 所以动画应该是:alpha 0 -> alpha 1 -> alpha 0 -> alpha 1 -> ...等等,持续时间为两秒。 你能帮帮我吗?
我的完整代码是
-(IBAction){
FirstViewController *firstViewController = [[[FirstViewController alloc] init]autorelease];
[firstViewController.label1 setAlpha:1.00];
[firstViewController.label2 setAlpha:1.00];
view = firstViewController.viewFirst; //this is my view and I copy in other view
[self fadeOut:nil finished:nil context:nil];}
- (void) fadeOut:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(fadeIn:finished:context:) ];
[view setAlpha:0.00];
[UIView commitAnimations];
}
- (void) fadeIn:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(fadeOut:finished:context:) ];
[view setAlpha:1.00];
[UIView commitAnimations];
}
最佳答案
在 iOS 4 及更高版本中你可以这样做
view1.alpha = 1.0;
[UIView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionRepeat|UIViewAnimationAutoReverse
animations:^{
view1.alpha = 0.0;
}
completion:nil
];
关于objective-c - iOS:简单的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6384532/