I don't think you can stop animations already scheduled. But you could set an instance variable with a BOOL
flag indicating if a button was already pressed or not.
For example, supposing your button's targets is the method buttonTapped
.
Initialize you flag to NO
.
- (id)init {
if (self = [super init]) {
buttonAlreadyTapped = NO;
}
return self;
}
In your button's targets set the flag to YES
.
- (void)buttonTapped {
self.buttonAlreadyTapped = YES;
}
And only modify the alpha
if the flag is NO
.
for (NSInteger i = 1; i <= [menuItems count]; i++) {
UIButton *menuItem = [menuItems objectAtIndex:i-1];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (3 * i) * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
if (!self.buttonAlreadyTapped) {
menuItem.alpha = 1.0f;
}
});
}
Remember that sending messages to UIKit
, should always be done on the main thread.
for (NSInteger i = 1; i <= [menuItems count]; i++) {
UIButton *menuItem = [menuItems objectAtIndex:i-1];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (3 * i) * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
if (!self.buttonAlreadyTapped) {
dispatch_async(dispatch_get_main_queue(), ^{
menuItem.alpha = 1.0f;
});
}
});
}