3 Replies
      Latest reply on Dec 10, 2015 10:42 AM by justin.voss
      Appersian Level 1 Level 1 (0 points)

        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 !

        • Re: didUpdateFocusInContext prevents number of taps
          justin.voss Apple Staff Apple Staff (260 points)

          Can you elaborate a bit more about what you're trying to do? The arrow buttons are going to be used by UIKit to move focus, so if the user double-taps on an arrow button, focus is going to try to move twice. It's possible that another gesture recognizer is getting to recognize first, which would prevent your double-tap gesture from firing. Are there any other gestures that you're adding that could be interfering?

            • Re: didUpdateFocusInContext prevents number of taps
              Appersian Level 1 Level 1 (0 points)

              Thanks for reply ! actually there are two gestures :

               

              UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(SwipeRecognizer:)];
                  swipe.direction  = (UISwipeGestureRecognizerDirectionLeft |
                                                 UISwipeGestureRecognizerDirectionRight |
                                                 UISwipeGestureRecognizerDirectionDown |
                                                 UISwipeGestureRecognizerDirectionUp);;
                  [self.view addGestureRecognizer:swipe];
                
                
                  UITapGestureRecognizer *openOrCloseInfoView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleInformationView:)];
                  openOrCloseInfoView.allowedPressTypes = @[[NSNumber numberWithInteger:UIPressTypePlayPause]];
                  [self.view addGestureRecognizer:openOrCloseInfoView];
              

               

              I am not sure the problem is because of them ! I think the custom button are the cause of this issue because I tested with default buttons and when tap twice the method will be triggered ! with no problem !