涉及多个视图时关于旋转的问题

发布于 2024-10-19 13:26:23 字数 340 浏览 1 评论 0原文

我是可可和可可的相对新手。为ipad编程。

我构建了一个具有分割视图控制器的应用程序。详细视图中有一个工具栏,上面有一个按钮。当按下按钮时,分割视图控制器将从超级视图中删除,并在其位置放置另一个视图。这个新视图上的工具栏按钮会删除该视图并恢复分割视图。效果很好...除非当 ipad 旋转而第二个视图可见时。当用户返回到分割视图时,它会按旋转之前的方式显示。

分割视图和所有子视图都设置为autoresize=yes,并在收到autorotatetointerfaceorientation消息时返回yes。

我猜当我将分割视图及其子视图作为子视图添加到窗口时,我需要告诉它自行调整大小。

谢谢 克里斯

I'm a relative newcomer to cocoa & programming for the ipad.

I've built an app that has a split view controller. In the detail view is a toolbar with a button on it. When the button is pressed, the split view controller is removed from the superview, and another view is put in its place. A toolbar button on this new view removes the view and puts the split view back. Works great... except when the ipad is rotated while the second view is visible. When the user returns to the split view, it's displayed as it was before the rotation.

The split view and all the sub views are set to autoresize=yes, and return yes when they receive the autorotatetointerfaceorientation message.

I'm guessing I need to tell the split view and its sub views to resize themselves when I add it as a subview to the window.

Thanks
Chris

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

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

发布评论

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

评论(2

真心难拥有 2024-10-26 13:26:24

请在此处查看我关于此事的问题:

最佳方法在 UISplitViewController 和其他视图控制器之间切换?

如果您按照 Apple 的意图使用 UISplitViewController,那么它的限制是相当有限的。

我最终使用了与您提到的完全相同的策略 - 即从 UIWindow 中删除 UISplitViewController 的视图,并用另一个替换,然后再切换回来。我发现方向更改已处理,即使我在呈现视图 B 时旋转(B 是非分割视图),然后切换回 A(分割视图)。然而,我必须对 uisplitview 的框架大小进行一些调整才能使其工作。稍后当我找到它时会更新更多信息。

还可以选择编写自己的分割视图控制器,或使用其他人的重新实现,例如:

http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad

更新

我对 UISplitView 的帧大小所做的摆弄可以在我的 AppDelegate 中的以下方法。这些方法用于通过替换 UIWindow 下的另一个顶级视图控制器来呈现分割视图控制器:

- (void)removeAllWindowSubviews {
    for (UIView *childView in window.subviews) {
        [childView removeFromSuperview];
    }
}

- (void)presentSplitView:(UISplitViewController *)vc {
    [self removeAllWindowSubviews];

    UIView *viewForSplitVC = vc.view;

    // fix for deficiency in adding a split view controller's view in landscape mode
    // and it still having a frame for portrait mode.
    // 2010-10-15 added -20.0f to fix problem with toolbar in LHS VC being 20 pix too low. 
    viewForSplitVC.frame = CGRectMake(viewForSplitVC.frame.origin.x, viewForSplitVC.frame.origin.y, 
                              navigationController.view.bounds.size.width, navigationController.view.bounds.size.height - 20.0f);    

    [window addSubview:viewForSplitVC];
}

// for removing the split view and restoring the other main VC
- (void)restoreMenu {
    if (isIPad()) {
        [self removeAllWindowSubviews];

        [window addSubview:navigationController.view];      
    }
}

正如我所说,这是一个 hack,但是框架的纠正使我能够呈现分割 VC,而其框架有时不正确。正如我之前指出的,通过做这些事情,我们超出了苹果希望我们做的事情,因此涉及到黑客行为。

Please see my question concerning this matter here:

Best way to switch between UISplitViewController and other view controllers?

If you use UISplitViewController as Apple intend you to, it's quite limited.

I ended up using a strategy exactly as you mention -- i.e. remove the UISplitViewController's view from UIWindow, and replace with another, and then later switch back. I found out that the orientation change WAS handled, even if I rotated while view B was presented (B being the non-split view), then switch back to A (the split view). However, I had to do a bit of fiddling with the frame size of the uisplitview to make it work. Will update with more info later when I find it.

There's also the option of writing your own split view controller, or using someone else's reimplementation, such as this one:

http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad

UPDATE

The fiddling I did with the frame size of UISplitView can be seen in the following method in my AppDelegate. These methods are for presenting the split view controller by replacing another top level view controller under UIWindow:

- (void)removeAllWindowSubviews {
    for (UIView *childView in window.subviews) {
        [childView removeFromSuperview];
    }
}

- (void)presentSplitView:(UISplitViewController *)vc {
    [self removeAllWindowSubviews];

    UIView *viewForSplitVC = vc.view;

    // fix for deficiency in adding a split view controller's view in landscape mode
    // and it still having a frame for portrait mode.
    // 2010-10-15 added -20.0f to fix problem with toolbar in LHS VC being 20 pix too low. 
    viewForSplitVC.frame = CGRectMake(viewForSplitVC.frame.origin.x, viewForSplitVC.frame.origin.y, 
                              navigationController.view.bounds.size.width, navigationController.view.bounds.size.height - 20.0f);    

    [window addSubview:viewForSplitVC];
}

// for removing the split view and restoring the other main VC
- (void)restoreMenu {
    if (isIPad()) {
        [self removeAllWindowSubviews];

        [window addSubview:navigationController.view];      
    }
}

As I said, it's a hack, but the correcting of the frame gave me the ability to present the split VC without its frame being sometimes incorrect. And as I noted earlier, by doing this stuff, we're going outside what Apple want us to do, hence the hackery involved.

风柔一江水 2024-10-26 13:26:24

好吧,我有一个可行的想法:不要从视图层次结构中删除 UISplitViewController 的视图。相反,可以在其之上放置一个视图,将其视图的 alpha 属性设置为 0 或将其视图的hidden 属性设置为 YES。

Ok, I have an idea for what might work: Don't remove the UISplitViewController's view from the view hierarchy. Instead, either put a view on top of it, set the alpha property of its view to 0 or set the hidden property of its view to YES.

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