UINavigationController后退按钮上的自定义过渡动画

Hou*_*nis 4 transactions objective-c navigationcontroller

我在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];
Run Code Online (Sandbox Code Playgroud)

但是这个过渡动画仅适用于Forw​​ard,我可以在Back上应用它吗?

谢谢

Man*_*lio 11

当然,只需为后退按钮定义一个自定义UIBarButtonItem并将其链接到一个自定义方法,该方法执行类似于推送控制器的操作,但不是推动您需要弹出视图控制器.

即首先创建后退按钮(在init或viewDidLoad方法中)

UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(back)];
self.navigationItem.leftBarButtonItem = backBarButtonItem;
[backBarButtonItem release];
Run Code Online (Sandbox Code Playgroud)

然后,在你的后方法中,你可以做自定义动画

-(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];


}
Run Code Online (Sandbox Code Playgroud)