2016-11-25 43 views
0

我有兩個UIimageview圖像可以使用touchesBegan和touchesMoved拖動,但是可以將它們拖動到屏幕上的任何位置,沒有任何限制。我試圖限制UIimageview只能在UIimage(某些區域)內拖動。swift xcode 8.0 - uiimageview在uiview中拖動

任何想法什麼是最好的方法?

感謝

回答

0

使用CGRectContainsPoint限制區域。

例如:

let point = touch.location(in: self) // or elsewhere 
if CGRectContainsPoint(image.frame, point) { 
    // could drag 
} else { 
    // stop dragging 
} 
+0

你是什麼意思 「touch.location」 – Alwin