【问题标题】:tvOS Gesture Recognizer stops working after sliding offscreentvOS 手势识别器在滑出屏幕后停止工作
【发布时间】:2019-12-23 19:40:52
【问题描述】:

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

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

-(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。

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

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

【问题讨论】:

    标签: uigesturerecognizer tvos


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多