ios – 如何将手势限制在UIImageView的范围内?

ios – 如何将手势限制在UIImageView的范围内?,第1张

概述我想限制黑色图像UIView在girlimageview bounds内移动.我不应该移动到girlimageview之外. 我的girlimageview是带框架的静态图像(5,0,310,320) 我正在使用UIGestureRecognizer在imageview上移动黑色图像. 我尝试使用UIPanGestureRecognizer进行下面的代码限制,但无法限制它. UIPanGestur 我想限制黑色图像UIVIEw在girlimagevIEw bounds内移动.我不应该移动到girlimagevIEw之外. @H_404_7@

@H_404_7@我的girlimagevIEw是带框架的静态图像(5,310,320)

@H_404_7@我正在使用UIGestureRecognizer在imagevIEw上移动黑色图像.

@H_404_7@我尝试使用UIPanGestureRecognizer进行下面的代码限制,但无法限制它.

@H_404_7@

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,blackanimatevIEw.frame.size.height);            blackanimatevIEw.frame = newframe;          }    }
@H_404_7@任何帮助,将不胜感激.

解决方法
- (voID)handlePan:(UIGestureRecognizer*)panGes {CGPoint point = [panGes locationInVIEw:girlimagevIEw];CGRect girlimageVIEwBounds = girlimagevIEw.bounds;CGRect blackAnimateVIEwFrame = blackanimatevIEw.frame;CGfloat newX = MIN(point.x,girlimageVIEwBounds.size.wIDth - blackAnimateVIEwFrame.size.wIDth);newX = MAX(newX,0.0f);CGfloat newY = MIN(point.y,girlimageVIEwBounds.size.height - blackAnimateVIEwFrame.size.height);newY = MAX(newY,0.0f);blackAnimateVIEwFrame.origin.x = newX;blackAnimateVIEwFrame.origin.y = newY;blackanimatevIEw.frame = blackAnimateVIEwFrame;}
@H_404_7@这是代码.如果黑色视图是女孩图像视图的子视图,它应该工作.

总结

以上是内存溢出为你收集整理的ios – 如何将手势限制在UIImageView的范围内?全部内容,希望文章能够帮你解决ios – 如何将手势限制在UIImageView的范围内?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1065285.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存