NavigationControllers之间的交互式动画过渡

时间:2014-12-02 22:49:23

标签: ios uiviewanimationtransition

使用:

呈现新的ViewController时
 UINavigtionController *nav = [[UINavigationController alloc] initWithRoot(myVC)]
 [self presentViewController:nav animated:YES completion:nil];

因为我在myVC中声明了这个,所以永远不会触发UIViewControllerTransitionDelegate。我的问题是:如何使用上述初始化正确设置交互式转换?

编辑:

我试图按照下面给出的建议,但没有运气:

VC1.m:

LTFollowersListViewController *f = [LTFollowersListViewController new];
f.delegate = self;
LTNavigationController *nav = [[LTNavigationController alloc] initWithRootViewController:f];

[self presentViewController:nav animated:YES completion:nil];

VC2.h:

@interface LTFollowersListViewController : UIViewController <UIViewControllerTransitioningDelegate>
@property (nonatomic, strong) id<UIViewControllerTransitioningDelegate> delegate;

VC2.m:

@property (nonatomic, strong) CEPanAnimationController *animationController;
@property (nonatomic, strong) CEHorizontalSwipeInteractionController *interactionController;
viewDidLoad中的

:{

self.delegate = self;
self.animationController = [[CEPanAnimationController alloc] init];
self.interactionController = [[CEHorizontalSwipeInteractionController alloc] init];
}
文件底部的

:     #pragma mark - UIViewControllerTransitionsingDelegate

- (id<UIViewControllerAnimatedTransitioning>)
animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source {
    NSLog(@"Reached the animation dismissal");

    // allow the interaction controller to wire-up its gesture recognisers
    [self.interactionController wireToViewController:self.navigationController forOperation:CEInteractionOperationDismiss];
    self.animationController.reverse = NO;
    return self.animationController;
}

- (id<UIViewControllerAnimatedTransitioning>)
animationControllerForDismissedController:(UIViewController *)dismissed {
    self.animationController.reverse = YES;
    return self.animationController;
}

- (id<UIViewControllerInteractiveTransitioning>)
interactionControllerForDismissal:
(id<UIViewControllerAnimatedTransitioning>)animator {
    NSLog(@"Reached the animation interaction");

    // provide the interaction controller, if an interactive transition is in progress
    return self.interactionController.interactionInProgress
    ? self.interactionController : nil;
}

有关我在这里缺少什么的建议吗?谢谢!

1 个答案:

答案 0 :(得分:0)

你错过了

.h文件声明委托和协议ViewController将实现

@interface ViewController : UIViewController<UIViewControllerTransitioningDelegate>

@property (nonatomic, strong) id<UIViewControllerTransitioningDelegate> delegate; 

.m文件设置代理

self.delegate = self;

并实现委托方法。