最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift中判断当前页面是否显示完毕

iOS crifan 2667浏览 0评论

折腾:

[已解决]iOS中进入页面后无故触发UIKeyboardWillShowNotification而显示键盘

期间,判断当前页面,是否显示完毕

即:是否已经进入:

viewWillAppear

或:

viewDidAppear

搜:

swift check view already show

swift check view already appear

ios – How to tell if UIViewController’s view is visible – Stack Overflow

swift check view appear

iphone – How to check if a specific UIViewController’s view is currently visible? – Stack Overflow

最后没找到。只能自己去手动定义一个变量去判断:

<code>   var isViewDidAppear:Bool

    init(curContactItem:ContactItem){

        self.isViewDidAppear = false

    }

//    override func viewDidDisappear(animated: Bool) {
//        super.viewDidDisappear(animated)
//        self.isViewDidAppear = false
//    }

    override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
 
        self.isViewDidAppear = false
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

        self.isViewDidAppear = true
    }
</code>

然后供后续判断:

<code>    func textViewShouldBeginEditing(textView: UITextView) -&gt; Bool {
        gLog.debug(&quot;self.inputTextView.isFirstResponder()=\(self.inputTextView.isFirstResponder()), self.view.isFirstResponder()=\(self.view.isFirstResponder()), self.isViewDidAppear=\(self.isViewDidAppear)&quot;)

        return self.isViewDidAppear
    }
</code>

转载请注明:在路上 » [已解决]swift中判断当前页面是否显示完毕

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.166 seconds, using 22.12MB memory