我正在翻译 Apple 的示例 Custom View Controller Presentations and Transitions (特别是 AAPLCustomPresentationController)到 Swift 中,我遇到了一个问题。
在他们的 preferredContentSizeDidChangeForChildContentContainer 方法(第 190 行)中,他们检查
- (void)preferredContentSizeDidChangeForChildContentContainer:(id<UIContentContainer>)container
{
[super preferredContentSizeDidChangeForChildContentContainer:container];
if (container == self.presentedViewController)
[self.containerView setNeedsLayout];
}
在 Swift (3.0) 中,我尝试过
if container == (self.presentedViewController as UIContentContainer)
但是我得到了错误
Binary operator '==' cannot be applied to two 'UIContentContainer' operands
我如何在 Swift 中执行此检查?
最佳答案
如果两个对象都是 UIViewController,是否可以在比较之前将它们转换为该类型?
if presentedViewController as? UIViewController == container as? UIViewController {
// true
}
关于ios - 在 Swift 中检查 UIContentContainer 是否为 ViewContoller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38124906/