2015-06-05 28 views
0

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

enter image description here

点击然后给出:

enter image description here

我如何能达到类似的效果任何想法?注意我不想关闭顶级工具栏,只需要MasterViewController。谢谢!

SOLUTION

感谢普拉,我在IBAction为最终的解决方案是:

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

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

回答

2

隐藏主视图

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]; 
     }]; 

我希望它会为你有用!

+0

谢谢Pravin!我用你的代码作为基础,但简化了一点。我用我的代码更新了我的答案。 – samturner

+0

@samturner:多数民众赞成在! –

相关问题