我看到很多第三方库。但我想自己做。
这是我正在尝试的:
__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 的:
当我点击 Button 时,我的屏幕会变成这样:
我以前的 VIewController 也在移动。
我想修复它。而且我也无法在某个时候停止它。
最佳答案
您可能想为此使用子 Controller 。
下面是演示此概念的非常简化的代码。它添加了一个 subview Controller 并将其动画化到屏幕中间。这至少应该给你一个起点:
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);
}];
关于ios - 如何将一个 ViewController 从左侧推到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35067471/