图片视图不应该使用UIPangesture移动到其超级视图之外
问题描述:
我使用UIPangesture来移动图像视图,并且此图像视图是类视图的子视图,当我移动图像视图时,它将移到其超视图之外。我想设置移动此imageview的边界,意味着imageview应该只在其超级视图内移动。图片视图不应该使用UIPangesture移动到其超级视图之外
答
我想在选择器中,通过平移手势调用的设置视图的中心或原点相应的平移点。
这是你的代码应该是什么样子,以解决您的问题:
- (void)thePanSelector:(id)sender{
UIPanGestureRecognizer *recognizer = (UIPanGestureRecognizer *)sender;
CGPoint p = [recognizer locationInView:theSuperView];
float boundedX = MAX(0,MIN(theSuperView.frame.size.width,p.x));
float boundedY = MAX(0,MIN(theSuperView.frame.size.height,p.y));
CGPoint boundedPoint = CGPointMake(boundedX,boundedY);
view.center = p;
}
这个代码是未经测试,所以你可能需要用一下boundedX的价值观和boundedY
@ajeet做你试试这个吗?你是如何解决你的问题的? – 2013-03-06 14:30:34