0
votes

I have a view that acts like the macOS dock - it can be moved offscreen entirely.

My gesture recognizer looks like:

-(void)swipeDown:(UISwipeGestureRecognizer *)sender
{
    NSLog(@"Swipe Down");

    // this should move the dock 10 pixels below the bottom of the screen
    [UIView animateWithDuration:0.5
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{[self dockView].frame = CGRectMake(kSafeMarginHorizontal, self.view.frame.size.height + 10, self.view.frame.size.width - (kSafeMarginHorizontal * 2), 80);}
                     completion:nil];
}

I am only using an autoresizing mask on my dockView with right and left edges pinned. In my main parent view I call:

    [[self view] setTranslatesAutoresizingMaskIntoConstraints:YES];

This works fine, but after sliding offscreen, the corresponding Swipe Up gesture no longer works and if I swipe down again, I no longer get the NSLog indicating the method was called.

I can prevent this by not sliding the view entirely offscreen. If I leave a least a few pixels on the screen, it continues to work ok.

Why does this break my gesture recognizer?

1

1 Answers

1
votes

It seems that tvOS does not like it when a focused button ends up offscreen. I have also changed this to animate by changing constraints. The key is calling setNeedsFocusUpdate at the end of the animation.

//  flush pending layout operations, then animate the constraint change
[[self view] layoutIfNeeded];
[UIView animateWithDuration:0.25
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction
                 animations:^{[[self dockViewConstraint] setConstant:1080];
                              [[self view] layoutIfNeeded];}
                  completion:^(BOOL finished){
                              // Do some cleanup after animating.
                              [self setNeedsFocusUpdate];}];