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

时间:2011-07-27 22:03:51

标签: objective-c transactions 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];

但是转换动画仅适用于Forw​​ard,我可以在Back上应用吗?

由于

1 个答案:

答案 0 :(得分:11)

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

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

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

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

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


}