Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 为什么';我的动画循环?_Objective C_Animation_Uiview_Uianimation - Fatal编程技术网

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];
        }];
    }];
}