2017-10-09 41 views
0

通過嘗試設置「Selected Box」圖形的界限來顯示用戶在UIImageView中的觸摸位置的組合。它仍然繼續堅持系統的超級意見協調將UIImageViews座標邊界用於另一個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

回答

0

讓selectedBox sodukoGrid的子視圖或更改您的抽頭位置相對於全局視圖。

let touchPoint = sender.locationInView(view) 
0

(發表代表作者問題作者)。從對方的回答

解只需添加的圖像對象作爲格柵圖像的用戶的建議後一個子視圖以下回答。

sodukoGrid.addSubview(selectedBox)