ada*_*dam 202 iphone cocoa-touch uiview uiwindow ios
的位置UIView
可以明显受到确定view.center
或view.frame
等等,但这只是返回的位置UIView
相对于它的即时上海华.
我需要确定UIView
整个320x480坐标系统的位置.例如,如果UIView
是在UITableViewCell
窗口内它的位置可以大大irregardless的上海华盈的改变.
任何想法是否以及如何可行?
干杯:)
Nik*_*uhe 331
这很简单:
[aView convertPoint:localPosition toView:nil];
Run Code Online (Sandbox Code Playgroud)
...将局部坐标空间中的点转换为窗口坐标.您可以使用此方法在窗口空间中计算视图的原点,如下所示:
[aView.superview convertPoint:aView.frame.origin toView:nil];
Run Code Online (Sandbox Code Playgroud)
2014编辑:看看Matt__C评论的受欢迎程度,似乎有理由指出坐标......
Yuc*_*ong 44
斯威夫特4:
let globalPoint = aView.superview?.convert(aView.frame.origin, to: nil)
Run Code Online (Sandbox Code Playgroud)
Shl*_*rtz 28
在Swift中:
let globalPoint = aView.superview?.convertPoint(aView.frame.origin, toView: nil)
Run Code Online (Sandbox Code Playgroud)
Moh*_*asm 26
Swift 3,扩展名:
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)
}
}
Run Code Online (Sandbox Code Playgroud)
Vla*_*eys 19
这是@Mohsenasm 的答案和@Ghigo 对 Swift 采纳的评论的结合
extension UIView {
var globalFrame: CGRect? {
let rootView = UIApplication.shared.keyWindow?.rootViewController?.view
return self.superview?.convert(self.frame, to: rootView)
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
107913 次 |
最近记录: |