【问题标题】:Hide MasterViewController from DetailViewController in a SplitViewController在 SplitViewController 中从 DetailViewController 隐藏 MasterViewController
【发布时间】:2015-06-06 05:15:18
【问题描述】:

我有一个 SplitViewController 设置有一个 DetailViewController 和一个 MasterViewController。 DetailViewController 包含一个地图,我想在地图上放置一个按钮,用于折叠和展开 MasterViewController。就像在 Apple 的 App Store 应用中一样:

点击按钮然后给出:

关于如何实现类似效果的任何想法?注意我不想关闭顶部工具栏,只是 MasterViewController。谢谢!

解决方案

感谢 Pravin,我在 IBAction 中的最终解决方案是:

if (self.splitViewController.preferredDisplayMode == UISplitViewControllerDisplayModePrimaryHidden) {
    self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
} else {
    self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
}

[UIView animateWithDuration:0.5 animations:^ {
     [self.splitViewController.view layoutIfNeeded];
 }];

【问题讨论】:

    标签: ios objective-c uisplitviewcontroller


    【解决方案1】:

    隐藏主视图

    AppDelegate * appDelegateObj = (AppDelegate *)[UIApplication sharedApplication].delegate;
            UISplitViewController * splitView = appDelegateObj.splitViewObj;
            splitView.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
            [UIView animateWithDuration:1.0 animations:^
             {
                 [spv.view layoutIfNeeded];
             }];
    
    show master view
    
    
    AppDelegate * appDelegateObj = (AppDelegate *)[UIApplication sharedApplication].delegate;
            UISplitViewController * splitView = appDelegateObj.splitViewObj;
            splitView.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
            [UIView animateWithDuration:1.0 animations:^
             {
                 [spv.view layoutIfNeeded];
             }];
    

    希望对你有用!

    【讨论】:

    • 谢谢普拉文!我以您的代码为基础,但对其进行了一些简化。我已经用我的代码更新了我的答案。
    • @samturner:太好了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多