【发布时间】:2014-07-23 13:26:28
【问题描述】:
我想要两个UIViewControllers 之间的转换,比如推送转换。
当我使用推送转换默认值时,我的视图从右到左转换。但我希望我的视图从左到右变换。
请指导一下
【问题讨论】:
-
能否给出代码示例?
标签: ios objective-c transform
我想要两个UIViewControllers 之间的转换,比如推送转换。
当我使用推送转换默认值时,我的视图从右到左转换。但我希望我的视图从左到右变换。
请指导一下
【问题讨论】:
标签: ios objective-c transform
这可能会有所帮助。虽然我相信一定有更好的办法。
UIViewController *vc = [[UIViewController alloc] init]; // create the new view controller to "push"
NSArray *viewControllers = self.navigationController.viewControllers;
NSMutableArray *mutableViewControllers = [viewControllers mutableCopy];
NSInteger indexOfSelf = [mutableViewControllers indexOfObject:self];
[mutableViewControllers insertObject:vc atIndex:indexOfSelf];
[self.navigationController setViewControllers:mutableViewControllers];
[self.navigationController popViewControllerAnimated:YES]; // actually, it's a "pop" action
【讨论】:
我采用了解决方案here 并对其进行了修改,使其看起来更干净,并从所需的方向推动。虽然它具有所需的方向动画,但导航栏中有一些我无法消除的闪烁。
CATransition *transition = [CATransition animation];
transition.duration = 0.4f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:yourViewControllerHere animated:NO];
还要记住,用户非常习惯于从右侧推入下一个视图控制器。在更改标准项目的外观/感觉中非常基本的内容之前请仔细考虑,因为您可能会混淆您的用户。
【讨论】:
UIBarButtonItem 并将其设置为左侧导航项。它看起来与默认的后退按钮略有不同,并失去了一些附带的好处。您只需要在上面的代码中反转方向并手动管理您的导航堆栈。