2017-03-07 5 views
1

사용자 지정 센터 단추 (UIButton)가있는 TabBarController가 있습니다. 목표는 사용자가 다른 ViewController에서 TabBarController로 돌아갈 때 불투명도를 애니메이션화하는 것입니다.UINavigationController - 대화 형 팝 제스처 인식기 진행률을 얻으려면

그래서 "멀리있는"사용자가 스 와이프 한 방식에 따라 센터 버튼의 불투명도를 0에서 1로 애니메이션하기 시작하려고합니다. interactivePopGestureRecognizer을 사용하고 있으므로 "진행"가장자리에서 스 와이프를 감지하는 것이 제 경우에 이상적입니다.

다른 방법이 있습니까? topViewController 가시성을 감지 했습니까?

+0

@BangOperator UITabBarItem이 아닌 UIButton입니다. – ZassX

+0

@BangOperator UITabBarController는 루트입니다. 그것은 모두 자신의 UINavigationController를 가진 많은 자식을가집니다. 그게 다야. – ZassX

답변

0

UINavigationControllerDelegate 당신은 UIPercentDrivenInteractiveTransition의 인스턴스를 얻을 수 네비게이션 컨트롤러를 위임에이 메소드를 호출 할 수있는이 대리자 메서드를

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

있습니다. 이 클래스 객체에는 속성이 있습니다.

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

    }]; 
}