tvOS 手势识别器在滑出屏幕后停止工作

tvOS Gesture Recognizer stops working after sliding offscreen

我有一个类似于 macOS dock 的视图 - 它可以完全移出屏幕。

我的手势识别器看起来像:

-(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];
}

我只在我的 dockView 上使用了一个自动调整大小的蒙版,并固定了左右边缘。在我的主要父视图中,我调用:

    [[self view] setTranslatesAutoresizingMaskIntoConstraints:YES];

这很好用,但是在滑出屏幕后,相应的向上滑动手势不再起作用,如果我再次向下滑动,我不再得到指示调用方法的 NSLog。

我可以通过不将视图完全滑出屏幕来防止这种情况发生。如果我在屏幕上留下至少几个像素,它会继续正常工作。

为什么这会破坏我的手势识别器?

tvOS 似乎不喜欢焦点按钮离开屏幕。我还通过更改约束将其更改为动画。关键是在动画结束时调用setNeedsFocusUpdate

//  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];}];