眾所周知,官方文檔明確說(shuō)明
Today Extension是無(wú)法彈出鍵盤的,也就是無(wú)法響應(yīng)文字輸入的操作。
但是可以另辟蹊徑,使用SLComposeViewController來(lái)實(shí)現(xiàn)彈出鍵盤的操作,將所有子控件都添加到SLComposeViewController上,然后present。
@objc(TodayViewController)
class TodayViewController: UIViewController, NCWidgetProviding {
fileprivate let editor = SLComposeViewController()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// 將需要自定義布局的子控件添加到 SLComposeViewController 上。
setupInterface()
// 彈出 SLComposeViewController
editor.modalTransitionStyle = .crossDissolve
self.present(editor, animated: true)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
// 不要忘記 dismiss,否則會(huì)造成程序崩潰。
self.dismiss(animated: false)
}
}
-
效果如下:
