自动旋转 iPad 子视图

发布于 2024-09-15 15:27:50 字数 493 浏览 3 评论 0原文

我正在开发一个大型应用程序,它有一个主视图,称为根视图,顶部有用于程序控制的工具栏。有许多附加视图覆盖“根”视图,但使工具栏可见 - 有一个弹出菜单可以控制在“根”视图上显示哪个子视图。请注意,我没有使用 splitview 控制器。

为了节省资源,我在第一次从菜单中选择不同的子视图的功能时初始化它们。所有子视图都是在IB中设计的。当 ipad 处于纵向模式时,当第一次选择子菜单时,所有自动旋转效果都很好,但是当 ipad 处于横向模式时,当应用程序首次启动且子视图首次启动时,它们不会旋转并显示在剪裁的肖像模式。他们似乎不知道 iPad 是旋转的。

如果我从“根”viewDidLoad 方法初始化所有子视图,则无论 ipad 启动时的方向如何,它们都会正确旋转。因此,如果我在“根”视图可见之前初始化子视图,那么一切都很好。如果我在“根”视图变得可见后初始化它们,则子视图似乎不会自动旋转。

由于涉及大量代码,我希望我已经解释得足够清楚,以便具有更多经验或洞察力的人可以让我走上正确的轨道。

谢谢吉姆

I have a large application that I am working on which has a primary view, call it a root view, with toolbar at the top for program control. There are a number of additional views that overlay the "root" view but leaving the toolbar visible - There is a popover menu that controls which sub view is show over the "root" view. Please note, I am not using a splitview controller.

To save resources I initialize the different sub views when their function is selected from the menu the first time. All the sub views have been designed in IB. When the ipad is in portrait mode when the submenus are first select all the auto rotation works just fine, however when the ipad is in a landscape orientation when the application is first started and the subviews are first launched, they are not rotated and shown in a clipped portrait mode. They don't appear to know that the iPad is rotated.

If I initialize all the sub views from the "root" viewDidLoad method, they they all rotate properly regardless of what orientation the ipad is when it is started. So if I initialize the subviews before the "root" view is visible, then all is well. If I initialized them after the "root" view becomes visible, the sub views don't appear to auto rotate.

As there is a lot of code involved, I hope I have explained this clear enough so someone with a more experience or insight might put me on the right track.

Thanks Jim

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

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

发布评论

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

评论(1

☆獨立☆ 2024-09-22 15:27:50

吉姆,
将子视图添加到主 UIWindow 时,添加子视图的顺序的更改可能会影响这些视图受设备初始方向的影响。例如,在一个带有导航控制器(在代码中创建)和视图控制器(在IB中创建)的应用程序中,无论初始方向如何,以下代码都会正确显示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

        [self.window addSubview:navigationController.view];
        [self.window addSubview:viewController.view];
        [self.window makeKeyAndVisible];

        return YES;
}

但是,当应用程序以横向模式启动(请注意窗口中 addSubview 调用的顺序):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
 UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

        [self.window addSubview:viewController.view];
        [self.window addSubview:navigationController.view];
        [self.window makeKeyAndVisible];

        return YES;
}

我会尝试更改添加子视图的顺序。希望这有帮助!

Jim,
When adding subviews to your main UIWindow, a change in the order in which you add them can affect how these views are affected by the initial orientation of the device. For example, in an App with a navigation controller (created in code) and a view controller (created in IB), the following code will display correctly regardless of the initial orientation:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

        [self.window addSubview:navigationController.view];
        [self.window addSubview:viewController.view];
        [self.window makeKeyAndVisible];

        return YES;
}

However, the following piece of code will be messed up when the app is started in landscape mode (note the order of the addSubview calls in window):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
 UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

        [self.window addSubview:viewController.view];
        [self.window addSubview:navigationController.view];
        [self.window makeKeyAndVisible];

        return YES;
}

I'd try changing the order in which you add the subviews. Hope this helps!

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