【问题标题】:UINavigationController - get interactive pop gesture recognizer progressUINavigationController - 获取交互式弹出手势识别器进度
【发布时间】:2017-03-07 15:04:30
【问题描述】:

我有 TabBarController,它有自定义中心按钮 (UIButton)。这里的目标是在用户从其他 ViewControllers 返回到 TabBarController 时为其不透明度设置动画。

所以我想要实现的是开始动画中心按钮的不透明度从 0 到 1,这取决于用户滑动的“距离”多远。 我正在使用interactivePopGestureRecognizer,因此检测边缘“进度”的滑动对于我的情况来说是理想的。

或者还有其他方法吗?也许检测 topViewController 可见性?

【问题讨论】:

  • @BangOperator 这是 UIButton 而不是 UITabBarItem。
  • @BangOperator UITabBarController 是根用户。它有很多孩子,都有自己的 UINavigationController。就是这样。

标签: ios swift uinavigationcontroller uitabbarcontroller


【解决方案1】:

我刚刚通过添加自定义目标解决了这个问题

self.navigationController?.interactivePopGestureRecognizer?.addTarget(self, action: #selector(CountdownsViewController.handlePopGesture))

然后

@objc func handlePopGesture ()
{
    viewtoanimate.alpha = self.transitionCoordinator!.percentComplete
}

【讨论】:

    【解决方案2】:

    我认为你不需要滑动进度的中间值,试试这个代码:

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
    
        id<UIViewControllerTransitionCoordinator> t = self.transitionCoordinator;
        BOOL b = [t animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
            aCustomView.alpha = 1.f;
        } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
    
        }];
    }
    
    - (void)viewWillDisappear:(BOOL)animated {
        [super viewWillDisappear:animated];
    
        id<UIViewControllerTransitionCoordinator> t = self.transitionCoordinator;
        BOOL b = [t animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
            aCustomView.alpha = 0.f;
        } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
    
        }];
    }
    

    【讨论】:

      【解决方案3】:

      UINavigationControllerDelegate 有这个委托方法

      - (nullable id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
                                interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController NS_AVAILABLE_IOS(7_0);
      

      您可以在导航控制器委托上调用此方法以获取UIPercentDrivenInteractiveTransition 的实例。这个类对象有一个属性

      @property (readonly) CGFloat percentComplete;
      

      使用它来查找转换完成的百分比。

      【讨论】:

      • 不错,看起来很有希望。知道如何从委托函数中获取 UIPercentDrivenInteractiveTransition 实例吗?
      猜你喜欢
      • 2013-09-27
      • 2014-06-22
      • 1970-01-01
      • 2020-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多