I have several custom buttons in my view and made them a custom focus animation with
didUpdateFocusInContext
,and I added a UITapGestureRecognizer
to the view that when user taps twice a method will run ! but the problem is when didUpdateFocusInContext
prevents to double tap action until the focused context
reaches its end (it means riches to the last button) then method will fire when there is no focusable context !!! how can prevent such thing ? Here is my code :- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator: (UIFocusAnimationCoordinator *)coordinator {
/
for (UIButton *mainButton in _nextPrevButton){
if (context.nextFocusedView == mainButton) {
[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:.40 initialSpringVelocity:.60 options:UIViewAnimationOptionAllowUserInteraction animations:^ {
context.nextFocusedView.transform = CGAffineTransformMakeScale(1.2, 1.2);
context.nextFocusedView.layer.shadowOffset = CGSizeMake(0, 0);
context.nextFocusedView.layer.shadowOpacity = 1;
context.nextFocusedView.layer.shadowRadius = 15;
context.nextFocusedView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
context.nextFocusedView.layer.shadowOpacity = 1;
} completion:nil];
} else {
[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:.40 initialSpringVelocity:.60 options:UIViewAnimationOptionAllowUserInteraction animations:^ {
context.previouslyFocusedView.transform = CGAffineTransformMakeScale(1, 1);
context.previouslyFocusedView.layer.shadowOpacity = 0;
} completion:nil];
}
}
if (context.nextFocusedView == _hereraFocused) { [self buttonFocused:context]; } else if (context.previouslyFocusedView == _hereraFocused) { [self buttonNotFocused:context]; }
if (context.nextFocusedView == _plateosaursFocused) { [self buttonFocused:context]; } else if (context.previouslyFocusedView == _plateosaursFocused) { [self buttonNotFocused:context]; }
if (context.nextFocusedView == _silesaursuFocused) { [self buttonFocused:context]; } else if (context.previouslyFocusedView == _silesaursuFocused) { [self buttonNotFocused:context]; }
}
Tapping methods :
- (void)viewDidLoad {
UITapGestureRecognizer *rightTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightTap:)];
[rightTap setAllowedPressTypes:@[@(UIPressTypeRightArrow)]]; [rightTap
setNumberOfTapsRequired:2]; [self.view addGestureRecognizer:rightTap];
}
- (void)handleRightTap:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateRecognized)
{ NSLog(@"Right Arrow"); }
}
I tried other states :
UIGestureRecognizerStateBegan / UIGestureRecognizerStateEnded / UIGestureRecognizerStateRecognized
but no success !