2017-03-07 31 views
1

我有TabBarController具有自定義中心按鈕(UIButton)。此處的目標是在用戶從其他ViewController返回到TabBarController時爲其不透明度設置動畫。UINavigationController - 獲取交互式流行手勢識別器進度

所以我想要實現的是開始動畫中心按鈕的不透明度從0到1,具體取決於「遠」用戶已被刷過。 我使用interactivePopGestureRecognizer,所以從邊緣「進度」檢測刷卡將是我的情況的理想選擇。

或者還有其他方法嗎?也許檢測到topViewController的可見性?

+0

@BangOperator它是UIButton而不是UITabBarItem。 – ZassX

+0

@BangOperator UITabBarController是root。它有許多孩子,都有自己的UINavigationController。就這樣。 – ZassX

回答

0

UINavigationControllerDelegate有此委託方法

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

你可以叫你的導航控制器委託這種方法來獲得的UIPercentDrivenInteractiveTransition一個實例。此類對象有一個屬性

@property (readonly) CGFloat percentComplete; 

使用此命令查找已完成轉換的百分比。

+0

不錯,看起來很有前途。 任何想法如何從委託函數獲取UIPercentDrivenInteractiveTransition實例? – ZassX

1

我只是解決了這個通過添加自定義目標

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

然後

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

我不認爲你需要的刷卡進步的中間值,試試這個代碼:

- (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) { 

    }]; 
}