我有一個UIView主視圖控制器裏面包含1 imageview.i移動imageview與此方法。如何在移動ImageView時保持UIView內的imageview?
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *aTouch = [touches anyObject];
if (aTouch.view == self.sub_View) {
CGPoint location = [aTouch locationInView:self.sub_View];
CGPoint previousLocation = [aTouch previousLocationInView:self.sub_View];
self.imageView.frame = CGRectOffset(self.imageView.frame, (location.x - previousLocation.x), (location.y - previousLocation.y));
}
}
Imageview move perfect。但是當我移動時,我必須保持UIView內的imageview。此代碼的問題是,當我移動ImageView時,它也移動到UIView之外。我必須保持UIView裏面的圖像和只能在UIView內移動。 請幫我解決這個問題。如何爲imageview設置邊界,以便它只能在UIView內部移動。
是什麼self.sub_View –
它是主視圖一個UIView包含imageview的 –