2017-10-09 5 views
0

UIImageView内でユーザーが触れる場所のみを表示する 'Selected Box'グラフィックスの境界を設定しようとする多くの組み合わせを行っています。それはまだスーパービューがシステム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) 
関連する問題