Determine if UIView is visible to the user?

前端 未结 12 1799
不知归路
不知归路 2020-12-07 15:21

is it possible to determine whether my UIView is visible to the user or not?

My View is added as subview several times into a Tab Bar

12条回答
  •  执念已碎
    2020-12-07 15:51

    This can help you figure out if your UIView is the top-most view. Can be helpful:

    let visibleBool = view.superview?.subviews.last?.isEqual(view)
    //have to check first whether it's nil (bc it's an optional) 
    //as well as the true/false 
    if let visibleBool = visibleBool where visibleBool { value
      //can be seen on top
    } else {
      //maybe can be seen but not the topmost view
    }
    

提交回复
热议问题