gpt4 book ai didi

ios - 使用另一个 UIImageView 的 UIImageViews 坐标范围

转载 作者:行者123 更新时间:2023-11-30 12:06:12 25 4
gpt4 key购买 nike

尝试设置“选定框”图形的边界的多种组合,该图形仅显示用户在 UIImageView 中触摸的位置。它仍然继续坚持 super View 坐标系

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

最佳答案

制作 selectedBox sodukoGrid 的 subview 或将您的点击位置更改为相对于全局 View 。

let touchPoint = sender.locationInView(view)

关于ios - 使用另一个 UIImageView 的 UIImageViews 坐标范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46643996/

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