objective-c - iOS:简单的动画

标签 objective-c ios animation alphablending

我想创建一个改变 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/

相关文章:

ios - 返回 NSDictionary - 好的程序设计?

ios - 如何动画更改状态栏样式?

javascript - 是否可以在单个层上拥有多个 KineticJS 动画?

Objective-C:typedef 一个 block ,在方法声明中使用它。我该如何实现?

iphone - UIApplication openURL后台

iphone - UITableView 单元格文本被截断

ios - UITableView reloadData 阻塞 UI,每秒更新很多

ios - 使用gdal2tiles将图像转换为maptiles

c# - 如何在c#和wpf中实现scrollviewer bouncing的动画?

javascript - jquery 动画和 css 动画之间的滞后