我看到很多第三方图书馆。但我想自己做。
以下是我的尝试:
__block UIViewController *sourceViewController = self;
NavigationDrawerVC *controller = [[NavigationDrawerVC alloc] initWithNibName:@"NavigationDrawerVC" bundle:nil];
__block UIViewController *destinationController = (UIViewController*)controller;
CATransition* transition = [CATransition animation];
transition.duration = 5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[sourceViewController.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
但我正在这样做o / p:
当我点击按钮我的屏幕更改时如下:
我以前的VIewController也在移动。
我想修复它。而且我也无法在某些时候阻止它。
答案 0 :(得分:1)
您可能希望考虑使用子控制器。
这是一个非常简化的代码,用于演示此概念。它添加了一个子视图控制器,并将其设置为屏幕中间的动画。这至少应该给你一个起点:
UIViewController *drawerVC = [[UIViewController alloc] init];
drawerVC.view.backgroundColor = [UIColor redColor];
[self addChildViewController:drawerVC];
drawerVC.view.frame = CGRectMake(-self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:drawerVC.view];
[drawerVC didMoveToParentViewController:self];
[UIView animateWithDuration:0.3 animations:^{
drawerVC.view.frame = CGRectOffset(drawerVC.view.frame, drawerVC.view.frame.size.width * 0.5, 0);
}];