我有一个父视图控制器,它充当UIPageViewController
和另一个UIViewController
(称为commentsViewController
)的容器。我想在inputAccessoryView
内显示commentsViewController
,但它似乎不起作用。我已将commentsViewController
添加到父级,如下所示:
commentsViewController = storyboard!.instantiateViewControllerWithIdentifier("CommentsViewController")! as! CommentsViewController
self.addChildViewController(commentsViewController)
self.view.addSubview(commentsViewController.view)
//...I have set some autolayout constraints here
commentsViewController.didMoveToParentViewController(self)
然后在CommentsViewController
内,我有以下内容:
@IBOutlet var customView: UIView!
override var inputAccessoryView: UIView {
return customView
}
override func canBecomeFirstResponder() -> Bool {
return true
}
override func viewDidLoad() {
super.viewDidLoad()
self.becomeFirstResponder()
}
不幸的是,这不起作用,并且没有显示inputAccessoryView ......任何人都可以看到我缺少的东西吗?
谢谢。
答案 0 :(得分:1)
事实证明,因为我在制作视图动画,becomeFirstResponder()
会自动返回false。动画完成后效果很好。