我在 UINavigationController 中进行了自定义转换,我使用的代码:
SecondView *newView = [[SecondView alloc] initWithNibName:nil bundle:nil];
[UIView beginAnimtaions:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown];
[self.navigationcontroller pushViewController:newView animated:NO];
[UIView commitAntimations];
[newView release];
但是那个过渡动画只适用于前进,我可以在后退吗?
谢谢
最佳答案
当然,只需为后退按钮定义一个自定义 UIBarButtonItem 并将其链接到一个自定义方法,该方法执行类似于推送 Controller 的操作,但您需要弹出 View Controller 而不是推送。
即首先创建后退按钮(在 init 或 viewDidLoad 方法中)
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(back)];
self.navigationItem.leftBarButtonItem = backBarButtonItem;
[backBarButtonItem release];
然后,在你的 back 方法中,你可以做你的自定义动画
-(IBAction)back {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:YES];
[[self navigationController] popViewControllerAnimated:NO];
[UIView commitAnimations];
}
关于objective-c - 后退按钮上的 UINavigationController 自定义过渡动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6851814/