iphone - 在 USplitView iOS 5.1 中加载和隐藏主视图

标签 iphone ios uisplitview

我在谷歌上搜索了很长时间,但没有得到解决方案,在 iOS 5.1 Master View 中,向右滑动时出现主视图,向左滑动时消失。

我想在单击详细 View 的按钮时加载主视图,这怎么可能?

下面的代码对我有用,主视图隐藏,但主视图的黑屏尺寸保留在主视图的位置。

- (void)hideMaster:(BOOL)hide {

  AppDelegate *appDelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
 UISplitViewController* spv = appDelegate.splitViewController;
 spv.delegate=self;
 self.hiddenMaster= hide;
 [spv willRotateToInterfaceOrientation:self.interfaceOrientation duration:0];
 [spv.view setNeedsLayout];     
 }


- (BOOL)splitViewController:(UISplitViewController*)svc shouldHideViewController: (UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation {

NSLog(@"Spv: I do %@show the master", (self.hiddenMaster?@"not ":@""));

return self.hiddenMaster;
}

提前致谢

最佳答案

据我了解,执行此操作的标准方法是:

  1. 在您的应用程序委托(delegate)文件中,您需要将初始 View Controller 之一设置为 UISplitViewControllerDelegate。如果您不在此处执行此操作,那么当您以纵向启动应用程序时,您将不会获得第一个按钮。例如:

    UINavigationController *masterNavigationController = [self.splitViewController.viewControllers objectAtIndex:0];
    MyMasterVC *master = [self.masterNavigationController.viewControllers objectAtIndex:0];
    self.splitViewController.delegate = master;
    
  2. 在 MyMasterVC.h 中将自己声明为 <UISplitViewControllerDelegate>通过修改接口(interface),如:

    @interface MyMasterVC : UIViewController <UISplitViewControllerDelegate>

  3. 在 MyMasterVC.m 中,您需要实现 UISplitViewControllerDelegate 的各种方法,即 described here in Apple's documentation

隐藏和显示 View Controller 的方法为您提供一个 UIBarButtonItem,然后您必须将其添加到详细 View Controller (例如,在 UIToolBar 或 UINavigationBar 中)或从中删除。

如果您在处理这个问题时遇到问题,斯坦福大学优秀的 Paul Hegarty 在 iTunesU 上的一场讲座中对此进行了很好的介绍(2010 年或 2011 年秋季 - 不记得了)。你真的应该看一看。 iOS5.1改变了MasterVC在类(class)中严格的“popover”方式的呈现方式,但我认为所描述的方法仍然有效。这是类(class)的早期部分,可能是第 5 课、第 6 课、第 7 课或类似的类(class)。我认为它被称为“分割 View ”或“iPad 分割 View ”或类似名称。

编辑: 这是第 7 课,名称为:“UIToolbar 和 iPad 应用程序”

关于iphone - 在 USplitView iOS 5.1 中加载和隐藏主视图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12706606/

相关文章:

iphone - 如何添加 videoPlayer 作为 subview ?

ios - 将 NSObject 转换为 double

ios - 将 watch 应用程序添加到 Flutter iOS 应用程序

ios - 将 NSURL 的内容写入数组

ios - 在 UISplitView 中更改 RootViewController

ios - NSURLRequest 的默认 setHTTPMethod 是什么?是 "POST"还是 "GET"?

ios - View 中的图像大于设备屏幕

ios - 如何更改 TextView 的文本颜色?

ios - 在 UISplitView 的主视图中实现统一的 UIBlurEffect

iphone - 如何解决 iPhone 中的问题 "Command/bin/sh failed with exit code 1"