【发布时间】:2016-04-19 10:32:18
【问题描述】:
我在主视图控制器中有一个 UIView,其中包含 1 个 imageview。我用这个方法移动了 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 移动完美。但是当我移动时,我必须将 imageview 保留在 UIView 中。这段代码的问题是,当我移动 imageview 时,它也会移到 UIView 之外。我必须将图像视图保留在 UIView 内,并且只能在 UIView 内移动。 请帮我解决这个问题。如何为 imageview 设置边界,使其只能在 UIView 内移动。
【问题讨论】:
-
什么是self.sub_View
-
它是主视图上的 UIview,其中包含 imageview
标签: ios objective-c uigesturerecognizer uitouch