不使用Cocos2D或其他框架,我想让一些UIButton按顺序闪烁,每个按钮间隔1秒。但只有第一个闪烁!任何建议将不胜感激。如何使按钮以编程方式按顺序闪烁
-(void)pressTimerButton{
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self selector:@selector(timerFires)
userInfo:nil repeats:YES];
[timer fire];
}
- (void) timerFires{
ComputerStringsArray_A=[[NSMutableArray alloc]init];
[ComputerStringsArray_A addObject:@"1"];
[ComputerStringsArray_A addObject:@"2"];
[ComputerStringsArray_A addObject:@"3"];
[ComputerStringsArray_A addObject:@"4"];
[ComputerStringsArray_A addObject:@"5"];
NoElementsInMutableArray = [ComputerStringsArray_A count];
NSString *ReadString = ComputerStringsArray_A[increment];
if ([ReadString isEqualToString:one]) {Button = Button_01;}
else if ([ReadString isEqualToString:two]) {Button = Button_02;}
else if ([ReadString isEqualToString:three]) {Button = Button_03;}
else if ([ReadString isEqualToString:four]) {Button = Button_04;}
else if ([ReadString isEqualToString:five]) {Button = Button_05;}
else if ([ReadString isEqualToString:six]) {Button = Button_06;}
else if ([ReadString isEqualToString:seven]) {Button = Button_07;}
else if ([ReadString isEqualToString:eight]) {Button = Button_08;}
else if ([ReadString isEqualToString:nine]) {Button = Button_09;}
[self FlashButton];
increment++;
//Don't try to flash a button beyond the length of the array
if (increment > NoElementsInMutableArray-1)
{
[timer invalidate];
timer = nil;
}
}
-(void) FlashButton
//- (void)FlashButton:(id)anElement
{
self.Button.alpha = 1.0f;
[UIView animateWithDuration:0.18
delay:0.7
options:
UIViewAnimationOptionCurveEaseInOut |
//UIViewAnimationOptionRepeat |
UIViewAnimationOptionAutoreverse |
UIViewAnimationOptionAllowUserInteraction
animations:^{
self.Button.alpha = 0.02f;
}
completion:^(BOOL finished){
//At the end of the flashing return opacity to 100% and color to white
self.Button.alpha = 1.0f;
Button.backgroundColor = [UIColor whiteColor];
}];
}
你是否想要像某些线性移动一样闪烁? –
我希望他们一个接一个闪烁:1..2..3..4..5..etc。当下面的按钮闪烁时,上一个按钮已经停止闪烁 – jeddi