我想在UIView的中心放置一条线。
override func draw(_ rect: CGRect) {
if let anchor = anchorView(){
print("Anchor x origin : \(anchor.bounds.origin.x)")
anchor.backgroundColor = UIColor.blue
timeline.start = CGPoint(x: anchor.bounds.origin.x + anchor.frame.width/2 , y: 0)
timeline.middle = CGPoint(x: timeline.start.x, y: anchor.frame.origin.y)
timeline.end = CGPoint(x: timeline.start.x, y: self.bounds.size.height)
timeline.draw(view: self.contentView)
}else{
print("this should not happen")
}
}
我得到UIView的x位置等于零
答案 0 :(得分:1)
UIView
的{{1}}可能就是您所需要的:
func convert(_ point: CGPoint, to view: UIView?) -> CGPoint
然后您可以使用let centerRelativeToTableView = anchor.superview!.convert(anchor.center, to: tableView)