Objective c 为什么';我的动画循环?
我需要在用户单击特定按钮后对图像执行闪烁效果。但我的代码不起作用:Objective c 为什么';我的动画循环?,objective-c,animation,uiview,uianimation,Objective C,Animation,Uiview,Uianimation,我需要在用户单击特定按钮后对图像执行闪烁效果。但我的代码不起作用: - (void)next { [UIView animateWithDuration:2.0f delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{ NSLog(@"Done"); // <- USED AS COUNTER [image setAlph
- (void)next
{
[UIView animateWithDuration:2.0f delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
NSLog(@"Done"); // <- USED AS COUNTER
[image setAlpha:0];
[image setAlpha:0.5];
} completion:nil];
}
-(无效)下一步
{
[UIView animateWithDuration:2.0f延迟:0选项:UIViewAnimationOption自动反转| UIViewAnimationOption重复动画:^{
NSLog(@“Done”);//我刚刚创建了一个测试项目,它闪烁的很好
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong)UIView *blinker;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.blinker = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
self.blinker.backgroundColor = [UIColor greenColor];
[self.view addSubview:self.blinker];
[self next];
}
- (void)next
{
[UIView animateWithDuration:2.0f delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
NSLog(@"Done"); // <- USED AS COUNTER
[self.blinker setAlpha:0];
[self.blinker setAlpha:0.5];
} completion:nil];
}
我不知道你为什么要数数,但希望这能有所帮助
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong)UIView *blinker;
@property (nonatomic,)NSInteger counter;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.blinker = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
self.blinker.backgroundColor = [UIColor greenColor];
[self.view addSubview:self.blinker];
[self next];
}
- (void)next
{
[UIView animateWithDuration:1.0 animations:^{
self.counter++;
NSLog(@"Counter: %@", @(self.counter));
self.blinker.alpha = 0.0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1.0 animations:^{
self.blinker.alpha = 1.0;
} completion:^(BOOL finished) {
//check to see if you want to continue blinking if so call next again
[self next];
}];
}];
}