gpt4 book ai didi

ios - 在 TableView 单元格中查找 UIView 的 x 位置

转载 作者:行者123 更新时间:2023-11-28 16:01:19 25 4
gpt4 key购买 nike

我想在 UIView 的中心放置一条线。

the line is not at the centre of my icon

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 位置等于零

最佳答案

UIViewfunc convert(_ point: CGPoint, to view: UIView?) -> CGPoint 可能是您需要的:

let centerRelativeToTableView = anchor.superview!.convert(anchor.center, to: tableView)

然后就可以使用centerRelativeToTableView.x

关于ios - 在 TableView 单元格中查找 UIView 的 x 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41032904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com