iPhone - Get Position of UIView within entire UIWindow

后端 未结 6 1411
长发绾君心
长发绾君心 2020-11-27 09:14

The position of a UIView can obviously be determined by view.center or view.frame etc. but this only returns the position of the

6条回答
  •  臣服心动
    2020-11-27 10:06

    Swift 3, with extension:

    extension UIView{
        var globalPoint :CGPoint? {
            return self.superview?.convert(self.frame.origin, to: nil)
        }
    
        var globalFrame :CGRect? {
            return self.superview?.convert(self.frame, to: nil)
        }
    }
    

提交回复
热议问题