加载不同的纵向/横向 UIView

发布于 2024-09-04 19:32:58 字数 332 浏览 3 评论 0原文

我有以下 View COntroller 结构:

ScrollViewController 景观视图控制器 PortraitViewController

每个都有自己的 .nib

该应用程序以横向模式启动,其中许多横向视图被添加到滚动视图中。每个横向视图都有其特定的纵向视图,因此我必须为每个视图分配类似的 ID。你能告诉我,如何在旋转设备时加载每个横向视图的特定纵向视图?

我必须制作两个滚动视图吗?一张拍风景,一张拍肖像?或者是否可以只滚动横向滚动视图并根据 ID 仅加载一个具有正确内容的纵向视图?我该如何实现呢?

数据来自属性列表。

提前致谢!

I have following View COntroller structure:

ScrollViewController
LandscapeViewController
PortraitViewController

Each with its own .nib

The app starts in landscape mode where many landscape views are added to a scrollview. Each landscape view has its specific portrait view, so I have to assign like ID's to each of this views. Can you tell me, how I can load the specific portrait view for each landscape view when rotating the device?

Do I have to make two scroll views? One for landscape, one for portrait? Or is it possible to just scroll through the landscape scrollview an load just one portrait view with the right content based on an ID? How could I implement that?

The data comes from a property list.

Thanks in advance!

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

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

发布评论

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

评论(1

夏九 2024-09-11 19:32:58

您可以在 UIViewController 中使用 shouldAutorotateToInterfaceOrientation 来提供您正在寻找的功能。在下面的示例中,我将切换视图以对应方向更改:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
    /* Switch to the portrait view or do any other custom layout changes for current Orientation */
       self.view = portraitView;
    } else if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
    /* Switch to the landscape view or do any other custom layout changes for current Orientation */
       self.view = landscapeView;
    }   
    return YES;
}

在您的情况下,您可以使用 shouldAutorotateToInterfaceOrientation 来调整视图大小或切换到相应的纵向视图。

希望有帮助。

You use the shouldAutorotateToInterfaceOrientation in your UIViewController to provide the functionality that you are looking for. In the example below I am switching the views to correspond to orientation changes:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
    /* Switch to the portrait view or do any other custom layout changes for current Orientation */
       self.view = portraitView;
    } else if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
    /* Switch to the landscape view or do any other custom layout changes for current Orientation */
       self.view = landscapeView;
    }   
    return YES;
}

In your case, you can use the shouldAutorotateToInterfaceOrientation to may be resize your views or switch to their corresponding portrait views.

Hope that helps.

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