我想限制黑色图像 UIView 在girlimageview 范围内移动。我不应该移动到girlimageview 之外。
我的girlimageview是带框架的静态图像(5,0,310,320)
我正在使用UIGestureRecognizer
在 imageview 上移动黑色图像。
我尝试使用以下代码UIPanGestureRecognizer
来限制但无法限制它。
UIPanGestureRecognizer *panTagGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[panTagGesture setDelegate:self];
[blackanimateview addGestureRecognizer:panTagGesture];
-(void) handlePan:(UIGestureRecognizer*)panGes{
CGPoint point = [panGes locationInView:girlimageview];
if (point.x < girlimageview.bounds.size.width) {
CGRect newframe = CGRectMake(point.x, point.y, blackanimateview.frame.size.width, blackanimateview.frame.size.height);
blackanimateview.frame = newframe;
}
if (point.y < girlimageview.bounds.size.height-160) {
CGRect newframe = CGRectMake(point.x, point.y, blackanimateview.frame.size.width, blackanimateview.frame.size.height);
blackanimateview.frame = newframe;
}
}
任何帮助,将不胜感激。