gpt4 book ai didi

ipad - 在 MG SplitViewController 中以纵向模式显示主视图和详细 View

转载 作者:行者123 更新时间:2023-12-02 04:05:25 24 4
gpt4 key购买 nike

我目前正在将 MGSplitViewController 集成到我的一个应用程序中,并且它可以正常工作。

但是我想修改它当前以纵向模式显示的方式。所以我希望在应用程序打开时以纵向模式显示主视图和详细 View Controller 。所以在按下导航栏按钮时,它将再次隐藏并显示左 Root View Controller 。

所以我将代码更改为

   - (BOOL)shouldShowMasterForInterfaceOrientation:(UIInterfaceOrientation)theOrientation
{
// Returns YES if master view should be shown directly embedded in the splitview, instead of hidden in a popover.
//return ((UIInterfaceOrientationIsLandscape(theOrientation)) ? _showsMasterInLandscape : _showsMasterInPortrait);

return YES;
}

现在纵向和横向模式都显示了我想要的 Root View Controller 和详细 View Controller ,但问题是导航栏按钮无法隐藏和显示左 Root View Controller 。

任何机构都这样做过?

最佳答案

而不是修改MGSplitViewController源或子类,您可以使用 showsMasterInPortrait MGSplitViewController 的属性(property)从您的应用程序代码中打开和关闭主控。这对我来说一直很好。

更新细节:

我不会使用 Split View Controller 提供的条形按钮项目——它对我们的目的并不太有用。相反,设置您自己的按钮,并带有一个切换 showsMasterInPortrait 的关联操作。 Split View Controller 的属性。要达到后者,请连接一个 socket 属性。如果您要在横向中隐藏按钮,您还需要按钮本身的 socket 。确保在 IB 中也正确连接。

在标题中,这意味着这样的事情:

@property(nonatomic,assign) IBOutlet MGSplitViewController* splitVC;
@property(nonatomic,assign) IBOutlet UIBarButtonItem* toggleButton;
- (IBAction)toggleMasterViewTouched:(id)sender;

在类定义中:
@synthesize splitVC, toggleButton;

- (IBAction)toggleMasterViewTouched:(id)sender
{
BOOL master_shown = !self.splitVC.showsMasterInPortrait;
// Note: toggle the button's label text and/or icon between "hide" and "show" versions
self.toggleButton.title = master_shown ? @"Hide Master" : @"Show Master";

self.splitVC.showsMasterInPortrait = master_shown;
}

如果您只希望按钮以纵向显示,您还需要在自动旋转时将其隐藏,因此响应旋转事件(仍在细节 Controller 中):
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
// hide when in landscape, show when in portrait
self.toggleButton.hidden = UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

希望这就是全部。您还需要在某处为 showMasterInPortrait 和切换按钮标签和可见性设置默认值,可能在 viewDidLoad 中。 .

关于ipad - 在 MG SplitViewController 中以纵向模式显示主视图和详细 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7905699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com