gpt4 book ai didi

ios - 检测 UISplitViewController 何时更改显示模式

转载 作者:行者123 更新时间:2023-12-01 19:44:26 24 4
gpt4 key购买 nike

我正在尝试使用 UISplitViewController ,其中辅助 Controller 应在 UISplitViewController 处于并排模式时公开“关闭”功能(通过按钮或按钮栏项目),但在其他时间应隐藏该功能。我试着把它放在辅助 View Controller 中:

override func viewWillAppear(_ animated: Bool) {
if splitViewController!.primaryHidden {
// hide the "close" UI artifact
} else {
// show the "close" UI artifact
}
}

这会在第一次显示辅助 View 时正确设置“关闭”函数的可见性,但如果 UISplitViewController 在展开和折叠之间切换(例如,通过旋转 iPhone 6s Plus),则不会再次调用此函数(这是有道理的,因为辅助 Controller 仍然可见)。因此,即使 UISplitViewController 更改模式,“关闭”功能仍保持其初始状态 - 隐藏或显示。

如何让“关闭”功能隐藏或显示以响应 UISplitViewController 模式的变化?

最佳答案

UIViewControllerShowDetailTargetDidChangeNotification通知:

// Sometimes view controllers that are using showViewController:sender and
// showDetailViewController:sender: will need to know when the split view
// controller environment above it has changed. This notification will be
// posted when that happens (for example, when a split view controller is
// collapsing or expanding). The NSNotification's object will be the view
// controller that caused the change.
UIKIT_EXTERN NSNotificationName const UIViewControllerShowDetailTargetDidChangeNotification NS_AVAILABLE_IOS(8_0);

使用如下
- (void)viewDidLoad{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showDetailTargetDidChange:) name:UIViewControllerShowDetailTargetDidChangeNotification object:self.splitViewController];
}

- (void)showDetailTargetDidChange:(NSNotification *)notification{
// changed from collapsed to expanded or vice versa
}

此 Apple 示例演示了表格单元格附件如何从纵向显示指示符(表示将发生推送)更改为在更改为横向 Split View时将其删除:
https://developer.apple.com/library/archive/samplecode/AdaptivePhotos/Introduction/Intro.html

请注意,在 iOS 13 beta 上,将 addObserver 与对象 nil 一起使用,因为目前存在一个错误,他们使用错误的对象发送通知。他们使用来自内部类集群的新 UISplitViewControllerPanelImpl 而不是 UISplitViewController 对象。
http://www.openradar.appspot.com/radar?id=4956722791710720

关于ios - 检测 UISplitViewController 何时更改显示模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50183373/

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