首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iOS13 UIViewController isModalInPresentation在ObjectiveC中没有设置器,因此无法设置?

iOS13 UIViewController isModalInPresentation在ObjectiveC中没有设置器,因此无法设置?
EN

Stack Overflow用户
提问于 2019-10-02 02:11:14
回答 2查看 2.3K关注 0票数 4

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

代码语言:javascript
运行
复制
self.isModalInPresentation = YES;

无法编译,并出现以下错误

代码语言:javascript
运行
复制
No setter method 'setIsModalInPresentation:' for assignment to property

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

代码语言:javascript
运行
复制
// 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));

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

代码语言:javascript
运行
复制
    // 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

这仅仅是苹果对ObjectiveC源代码的疏忽吗?我找不到任何setIsModalInPresentation函数,也无法通过_isModalInPresentation直接访问它。我已经有一段时间没有在ObjectiveC中做任何有意义的工作了,所以我的语言知识已经生疏了,我需要在我的子类中合成属性吗?因为已经实现了一个getter,我甚至不确定它是如何工作的。

我使用的是Xcode11.0,我想我可以看看在Xcode/iOS的更高版本中是否修复了这个问题?

我们将一如既往地感谢任何帮助,干杯

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-10-02 02:22:12

试试这个:

self.modalInPresentation = YES;

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

代码语言:javascript
运行
复制
@property (nonatomic, getter=isModalInPresentation) BOOL modalInPresentation;

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

票数 10
EN

Stack Overflow用户

发布于 2019-10-16 01:35:44

使用API可用性检查可以很好地做到这一点!

代码语言:javascript
运行
复制
VSDrawViewController *drawViewController = [[VSDrawViewController alloc] init];
// .. setup delegate and stuff, if needed.
if (@available(iOS 13.0, *)) {
    drawViewController.modalInPresentation = YES;
} else {
    // Handle old iOS changes
}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58190206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档