ViewController.swift:
@IBOutlet weak var myView: MyView! {
didSet{
let p: CGPoint = myView.convertPoint(myView.center, fromView: myView.superview)
print("(p)")
}
MyView.swift:
override func drawRect(rect: CGRect) {
print( "(convertPoint(center, fromView: superview))")
}
输出:
(300.0, 268.0)
(187.5, 301.5)
第二个是正确的重点,第一个明显不对