从屏幕右侧打开另一个视图控制器视图

发布于 2024-10-09 01:19:03 字数 191 浏览 3 评论 0原文

我想从屏幕右侧打开一个视图控制器。

那就是在做

[自我呈现ModalViewController:pvc动画:是];

我希望另一个视图控制器的视图看起来好像是从屏幕右侧滑动的,而不是看起来好像是从屏幕底部来的:)

我怎样才能实现这一点。请帮忙:)

I want to open a viewcontroller from right side of the screen.

That is on doing

[self presentModalViewController:pvc animated:YES];

I want the another viewcontroller's view to appear as if its sliding from the right of the screen instead of appearing as if it is coming from the bottom of the screen :)

How can I achieve that. Please help :)

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

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

发布评论

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

评论(2

那请放手 2024-10-16 01:19:03

您正在寻找的是 UINavigationController。

在您的应用程序委托中,您将在 applicationDidFinishLoading 中看到如下所示的一行:

[window addSubview:viewController.view];

将该行更改为:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
[window addSubview:navController.view];

Now 而不是 [selfpresentModalViewController:pcvanimated:YES];可以做:

[self.navigationController pushViewController:pcv animated:YES];

这是一个给出“从右侧滑入”动画的控件。 Plus 允许您更好地控制应用程序内的视图堆栈和导航。这是控制应用程序中导航的最佳方式。

ps: navController 现在会泄漏 - 就像我的示例中的这样,这样你就可以看到我在做什么。您需要在应用程序委托的 .h 中将 navController 设为 iVar,以便可以在 dealloc 中释放它。如果您像现在一样释放它,那么您将无法向其发送消息。

What you are looking for is a UINavigationController.

In your app delegate you will have a line that looks like this in applicationDidFinishLoading:

[window addSubview:viewController.view];

Change that line to these:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
[window addSubview:navController.view];

Now instead of [self presentModalViewController:pcv animated:YES]; you can do:

[self.navigationController pushViewController:pcv animated:YES];

This is the control which gives the "slide in from the right" animation. Plus allows you to better control a view stack and navigation within an app. Its the best way to control navigation in your app.

ps: that navController will leak now - its just like this in my example so you can see what I'm doing. You'll want to make the navController an iVar in the .h of your app delegate so you can release it in dealloc. If you release it like it is now then you won't be able to send messages to it.

临风闻羌笛 2024-10-16 01:19:03

Look into UINavigationController - Class Reference. This lets you organize a hierarchy that will slide in from the side. Or you can play with the UIView animation blocks. Figure out whats best for your app. If you have several things you will be pushing from the side, like categories, use UINavigationController. If you just have a simple view you want to come in from the side and leave, you'll want to use the UIView animation or other animation methods. The UIView animation will look like this:

[UIView beginAnimations:nil context:nil];
//code to move view on to screen
[UIView setAnimationDuration:0.5];
[UIView commitAnimations];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文