iOS13 UIViewController isModalInPresentation 在 ObjectiveC 中没有设置器所以不能设置?

jim*_*buk 3 uiviewcontroller ios ios13

我正在尝试对我用 ObjectiveC 编写的应用程序进行一些更新,以采用新的 iOS 13 功能。我正在研究以模态呈现视图控制器的新方式的交互式解除处理,在检测到控制器中的更改后,我希望停止交互式解除并按照 Apple 的建议向用户呈现对话。尝试使用以下代码执行此操作

self.isModalInPresentation = YES;
Run Code Online (Sandbox Code Playgroud)

不编译并出现以下错误

No setter method 'setIsModalInPresentation:' for assignment to property
Run Code Online (Sandbox Code Playgroud)

从我的 ObjectiveC 项目转到此属性的实现转到 ObjectiveC 标头,其属性定义如下

// modalInPresentation is set on the view controller when you wish to force the presentation hosting the view controller into modal behavior. When this is active, the presentation will prevent interactive dismiss and ignore events outside of the presented view controller's bounds until this is set to NO.
@property (nonatomic, getter=isModalInPresentation) BOOL modalInPresentation API_AVAILABLE(ios(13.0));
Run Code Online (Sandbox Code Playgroud)

在 swift 项目中查看相同的属性会发现它的以下 swift 定义

    // modalInPresentation is set on the view controller when you wish to force the presentation hosting the view controller into modal behavior. When this is active, the presentation will prevent interactive dismiss and ignore events outside of the presented view controller's bounds until this is set to NO.
    @available(iOS 13.0, *)
    open var isModalInPresentation: Bool
Run Code Online (Sandbox Code Playgroud)

这只是 Apple 对 ObjectiveC 源代码的疏忽吗?我找不到任何 setIsModalInPresentation 函数或直接通过 _isModalInPresentation 访问它。我已经有一段时间没有在 ObjectiveC 中做任何重要的工作了,所以我的语言知识生疏了,我是否希望在我的子类中综合属性?由于已经实现了一个 getter,我什至不确定它是如何工作的。

我在 Xcode 11.0 上,我想我可以看看这是否在更高版本的 Xcode/iOS 中修复?

任何帮助一如既往的赞赏,干杯

ade*_*dev 8

尝试这个:

self.modalInPresentation = YES;

如上所述,它的定义如下,

@property (nonatomic, getter=isModalInPresentation) BOOL modalInPresentation;
Run Code Online (Sandbox Code Playgroud)

这意味着您需要将其设置为self.modalInPresentation = YES;. isModalInPresentation是一个吸气剂。


foo*_*bar 7

很高兴通过 API 可用性检查来做到这一点!

VSDrawViewController *drawViewController = [[VSDrawViewController alloc] init];
// .. setup delegate and stuff, if needed.
if (@available(iOS 13.0, *)) {
    drawViewController.modalInPresentation = YES;
} else {
    // Handle old iOS changes
}
Run Code Online (Sandbox Code Playgroud)