iOS(swift)退出/关闭共享扩展中的预选textView

时间:2019-05-27 15:14:47

标签: ios swift

在启动iOS共享扩展时,默认情况下将已选择/输入textView。 (键盘将可见,textView将处于编辑模式)

我不希望发生这种情况,如何以编程方式退出textView

override func viewDidLoad() {
  self.textView.exit() // obviously doesn't work
}

我看到大量关于用户在键盘上按Enter键时如何退出的帖子,我不想在“委托时”这样做,我只是希望扩展程序启动时textview不在编辑模式下(在viewDidLoad

我也尝试过(如其他文章所建议)

self.textView.endEditing(true)

没有隐藏键盘或退出textView

1 个答案:

答案 0 :(得分:1)

您可以在textView.resignFirstResponder()中致电presentationAnimationDidFinish

class ShareViewController: SLComposeServiceViewController {

    var textViewTintColor: UIColor?

    override func viewDidLoad() {
        super.viewDidLoad()

        // hide cursor which appears during presentation animation
        self.textViewTintColor = self.textView.tintColor
        self.textView.tintColor = .clear
    }

    override func presentationAnimationDidFinish() {
        super.presentationAnimationDidFinish()

        guard let tintColor = self.textViewTintColor else { return }

        self.textView.resignFirstResponder()

        // reset cursor
        self.textView.tintColor = tintColor
        self.textViewTintColor = nil
    }

}