如何仅在 SplitView 中的横向模式下隐藏 rootView 控制器

发布于 2024-11-06 09:35:27 字数 1185 浏览 2 评论 0原文

现在我有代码允许我隐藏代表 rootView 控制器的侧栏。当我进入横向模式时,“根列表”按钮被“隐藏侧边栏”按钮替换,单击时它会从 splitView 中删除 RootViewController。以下是在 AppDelegate 中找到的代码:

//Thanks to Alice McGregor for the code!!!
- (IBAction)toggleSplitView:(id)sender {
    if ( [window.subviews containsObject:splitViewController.view] ) {

        [splitViewController.view removeFromSuperview];

        splitViewController.viewControllers = [NSArray arrayWithObjects:rootViewController, rootViewController, nil];

        [window addSubview:detailViewController.view];

        [(UIBarButtonItem *)sender setTitle:@"Show Sidebar"];

    } else {

        [detailViewController.view removeFromSuperview];
        [detailViewController.view setTransform:CGAffineTransformIdentity];

        splitViewController.viewControllers = [NSArray arrayWithObjects:rootViewController,     detailViewController, nil];

        [window addSubview:splitViewController.view];
        [detailViewController.view sizeToFit];

        [(UIBarButtonItem *)sender setTitle:@"Hide Sidebar"];
    }
}

当选择隐藏侧边栏按钮时,这将删除 rootView(表)。但是,当您切换到纵向模式时,根列表按钮不存在,而是被“显示侧边栏”按钮取代。

我需要这样做,以便在横向模式下隐藏表格,但您仍然可以在纵向模式下选择根列表按钮。有什么想法吗?

Right now I have code that allows me to hide the side bar which represents the rootView Controller. When I go into landscape mode the "root list" button is replaced by a "hide sidebar" button and when clicked it removes the RootViewController from the splitView. Here is the code found in the AppDelegate:

//Thanks to Alice McGregor for the code!!!
- (IBAction)toggleSplitView:(id)sender {
    if ( [window.subviews containsObject:splitViewController.view] ) {

        [splitViewController.view removeFromSuperview];

        splitViewController.viewControllers = [NSArray arrayWithObjects:rootViewController, rootViewController, nil];

        [window addSubview:detailViewController.view];

        [(UIBarButtonItem *)sender setTitle:@"Show Sidebar"];

    } else {

        [detailViewController.view removeFromSuperview];
        [detailViewController.view setTransform:CGAffineTransformIdentity];

        splitViewController.viewControllers = [NSArray arrayWithObjects:rootViewController,     detailViewController, nil];

        [window addSubview:splitViewController.view];
        [detailViewController.view sizeToFit];

        [(UIBarButtonItem *)sender setTitle:@"Hide Sidebar"];
    }
}

This removes the rootView (table) when the hide sidebar button is selected. However, when you flip to portrait mode, the root list button isn't there and is instead replaced by the "show sidebar" button.

I need to make this so that when in landscape mode, the table is hidden, however you can still select the root list button in portrait mode. Any ideas?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文