2017-07-02 79 views
0

任何機構可以建議如何獲得圖像的x和y座標在鼠標單擊或觸摸時,當我點擊圖像內部的圖像視圖。如何獲得圖像的X和Y座標當我點擊(迅速)

感謝

+0

UITapGestureRecognizer可能會這樣做:https://stackoverflow.com/questions/16618109/how-to-get-uitouch-location-from-uigesturerecognizer – chedabob

回答

1

首先,點擊手勢監聽器添加到您的圖像視圖

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped(tapGestureRecognizer:))) 
imageView.isUserInteractionEnabled = true 
imageView.addGestureRecognizer(tapGestureRecognizer) 

然後在你的處理程序中,發現水龍頭的位置,你的形象是這樣看待

func imageTapped(tapGestureRecognizer: UITapGestureRecognizer) 
{ 
    let cgpoint = tapGestureRecognizer.location(in: imageView) 

    print(cgpoint) 
} 
相關問題