当对象移动到特定帧时如何停止 UIPanGestureRecognizer
我有一个使用 UIPanGestureRecognizer 移动的图像类型的对象,当该对象到达某个帧时,我需要停止识别 UIPanGestureRecognizer。
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[templatePhotoPlaceholderView addGestureRecognizer:panRecognizer];
-(void)move:(UIPanGestureRecognizer *)gestureRecognizer
{
CGPoint translatedPoint = [gestureRecognizer translationInView:templatePhotoPlaceholderView];
if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
_firstX = [imageview center].x;
_firstY = [imageview center].y;
}
translatedPoint = CGPointMake(_firstX+translatedPoint.x, _firstY+translatedPoint.y);
//NSLog(@" Move center point :%@", NSStringFromCGPoint(translatedPoint));
[imageview setCenter:translatedPoint];
}
我该怎么做?
I have an object of image type which I am moving using UIPanGestureRecognizer, and I need to stop recognizing the UIPanGestureRecognizer when the object reaches a certain frame.
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[templatePhotoPlaceholderView addGestureRecognizer:panRecognizer];
-(void)move:(UIPanGestureRecognizer *)gestureRecognizer
{
CGPoint translatedPoint = [gestureRecognizer translationInView:templatePhotoPlaceholderView];
if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
_firstX = [imageview center].x;
_firstY = [imageview center].y;
}
translatedPoint = CGPointMake(_firstX+translatedPoint.x, _firstY+translatedPoint.y);
//NSLog(@" Move center point :%@", NSStringFromCGPoint(translatedPoint));
[imageview setCenter:translatedPoint];
}
How may I do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
设置pangesture.delegate=self,并实现delegate方法
Set the pangesture.delegate=self, and implement delegate method
UIGestureRecognizers 有一个启用属性。文档:
编辑:
只需将启用属性设置为“否”。
UIGestureRecognizers have an enabled property. Documentation:
EDIT:
Just set the enabled property to NO.
当您需要阻止 UIPanGestureRecognizer 识别手势时,只需将此代码行(如 jbat100 所说)放入
-(void)move:(UIPanGestureRecognizer *)gestureRecognizer
中:在此行之后,您的gestureRecognizer状态设置为
"UIGestureRecognizerStateCancelled"
然后只需将几行添加到您的
-(void)move:(UIPanGestureRecognizer *)gestureRecognizer
函数:您将能够使用手势识别器
编辑:
这是代码片段:
When you need to stop your UIPanGestureRecognizer from recognizing gesture, you just put this code line (as jbat100 said) in
-(void)move:(UIPanGestureRecognizer *)gestureRecognizer
:after this line your gestureRecognizer state set as
"UIGestureRecognizerStateCancelled"
then just add couple lines to your
-(void)move:(UIPanGestureRecognizer *)gestureRecognizer
function:and you'll be able to work with your gesture recognizer
EDIT:
Here's code snippet: