【问题标题】:iOS (swift) exit/dismiss preselect textView in share extensioniOS(swift)退出/关闭共享扩展中的预选文本视图
【发布时间】:2019-05-27 23:51:19
【问题描述】:

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

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

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

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

我也尝试过(如其他帖子中所建议的)

self.textView.endEditing(true)

没有隐藏键盘或退出textView

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    您可以在presentationAnimationDidFinish中拨打textView.resignFirstResponder()

    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
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-05
      • 1970-01-01
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多