不同布局的旋转 - iOS 4

发布于 2024-11-04 04:15:01 字数 1359 浏览 2 评论 0原文

以下是我希望在应用程序中使用的两种布局。如果应用程序从纵向切换到横向时能够保留 UILabels、BOOL 和其他对象,那就太好了。因为按钮的位置不同,所以我不能只在自动旋转时让纵向视图自动调整大小。我还想使用 BOOL 和右上角的按钮来实现我自己的旋转锁。

我考虑过使用 -(void)orientationChanged:(NSNotification )notificationpresentModalViewController 但这些并没有复制对象,似乎导致 弊大于利,而且似乎无法正常工作

感谢您的帮助!

肖像 xib Landscape xib

尝试的解决方案:

我将横向视图添加到 ViewController 中,在视图控制器。我将其链接到我在 ViewController 的 @interface 部分中添加的 UIView *landscapeView 下的文件所有者。我将 [self.view addSubview:landscapeView] 添加到 viewDidLoad 方法中。然后我添加了这段代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if (orientationLock)
        return NO;
    else {
        if (interfaceOrientation == UIInterfaceOrientationPortrait) {
            [landscapeView setHidden:YES];
            //[self.view setHidden:NO]; removed
        } else {
            //[self.view setHidden:YES]; removed
            [landscapeView setHidden:NO];
        }
        return YES;
    }
}

但这不是正确的解决方案。当我运行模拟器并旋转它时,屏幕未正确放置。

坏图片

The following are the two layouts that I want have in my application. It would be nice if when the application switches from portrait to landscape that it keeps the UILabels, BOOLs, and other objects. Because the buttons are situated differently I cannot just have the portrait view autoresize on an auto rotate. I also want to implement my own rotation lock using a BOOL and the button on the top right.

I thought about using a -(void)orientationChanged:(NSNotification )notification with a presentModalViewController however these didn't copy over the objects and seemed to cause more harm then good and didn't appear to work properly.

Thanks for the help!

Portrait xib
Landscape xib

Attempted Solutions:

I added the landscape view to the ViewController, having both views in the view controller. I linked it up to File's Owner under the UIView *landscapeView that I added in the @interface section of the ViewController. I added [self.view addSubview:landscapeView] to the viewDidLoad method. Then I added this piece of code:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if (orientationLock)
        return NO;
    else {
        if (interfaceOrientation == UIInterfaceOrientationPortrait) {
            [landscapeView setHidden:YES];
            //[self.view setHidden:NO]; removed
        } else {
            //[self.view setHidden:YES]; removed
            [landscapeView setHidden:NO];
        }
        return YES;
    }
}

However this is not the correct solution. When I run the simulator and rotate it, the screen is not properly placed.

Bad Image

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

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

发布评论

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

评论(1

最后的乘客 2024-11-11 04:15:01

当设备改变方向时,所有事情(您的实例变量值)保持不变。如果你只有一个 viewController 并且你在同一个视图中显示两个方向,那么你可以轻松管理这一点。我建议你在 nib 文件中创建两个 UIView,这样你就可以做你想做的所有事情。希望你明白我在说什么。如果你需要帮助,请告诉我。

这是修改后的代码

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (orientationLock)
    return NO;
else {
    if (interfaceOrientation == UIInterfaceOrientationPortrait) {
        [landscapeView setHidden:YES];

    } else {

        [landscapeView setHidden:NO];
    }
    return YES;
}
}

All things(your instance variables values) remains same when the device changes orientation. If you have only one viewController and you are showing both orieantation in the same then you can easily manage this. I suggest you to create two UIViews in the nib file that way you can do all the things you want.Hope you understand what I am talking about.Let me know if you need help.

Here is modified code

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (orientationLock)
    return NO;
else {
    if (interfaceOrientation == UIInterfaceOrientationPortrait) {
        [landscapeView setHidden:YES];

    } else {

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