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

发布于 2024-11-26 11:08:24 字数 457 浏览 1 评论 0原文

我在 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];

但是该转换动画仅适用于前进,我可以将其应用到后退吗?

谢谢

I made a custom transition in UINavigationController, code I used:

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

But that transition animation applies only on Forward, can I apply it on Back?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港小镇 2024-12-03 11:08:24

当然,只需为后退按钮定义一个自定义 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];


}

Of course, simply define a custom UIBarButtonItem for back button and link it to a custom method that do something similar you do to push the controller, but instead of pushing you'll need to pop the view controller.

i.e. first you create your back button (in init or viewDidLoad method)

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

then, in your back method, you can do your custom animation

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


}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文