【发布时间】:2017-10-09 10:12:36
【问题描述】:
尝试设置“选定框”图形的边界,以显示用户仅在 UIImageView 中触摸的位置。它仍然继续坚持超级视图坐标系
class ViewController: UIViewController {
@IBOutlet weak var selectedBox: UIImageView!
@IBOutlet weak var sodukoGrid: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
selectedBox.hidden = true
selectedBox.frame.origin.x = sodukoGrid.bounds.minX
selectedBox.frame.origin.y = sodukoGrid.bounds.minY
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("tapAction:"))
self.sodukoGrid.userInteractionEnabled = true
self.sodukoGrid.addGestureRecognizer(tapGestureRecognizer)
}
func tapAction(sender: UITapGestureRecognizer) {
let touchPoint = sender.locationInView(self.sodukoGrid)
print(touchPoint)
selectedBox.center.x = CGFloat(touchPoint.x)
selectedBox.center.y = CGFloat(touchPoint.y)
}
Image showing the selected box graphic still sticking to the superviews bounds
【问题讨论】: