iOS:对象重叠时禁用平移手势 [英] iOS: disable pan gesture when objects overlap
本文介绍了iOS:对象重叠时禁用平移手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Pan Gesture
移动了一些对象.现在,我希望对象在以下任一情况下停止永久移动:
I have a few objects moved by using Pan Gesture
. Now I want the object to stop moving permanently when either:
- 它与特定的(固定的,无法移动的)对象重叠, 或
- 它会输入一定范围的位置.
- It overlaps a particular (stationary, not able to be moved) object, or
- It enters a certain range of locations.
当两个对象重叠时,我尝试使用removeGestureRecogniser
停止它,但是它不起作用.
I've tried to stop it when the two objects overlap using removeGestureRecogniser
but it didn't work.
- (IBAction)cowimagemove:(UIPanGestureRecognizer *)recognizer {
if (cowimage.center.x==stayimage.center.x) {
[self removeGestureRecogniser];
}
else {
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}
}
推荐答案
尝试捕获UIGestureRecognizer委托中的重叠项.
Try catching the overlap in your UIGestureRecognizer Delegate.
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ([self checkForOverlap:gestureRecognizer]) {
return NO;
}
return YES;
}
在checkForOverlap
方法中,您使用手势识别器对象测试相关点等,如果是这种情况,则返回YES.
In your checkForOverlap
method you use the gesture recognizer object to test for the relevant points etc. and return YES if it is the case.
(当然,上面的缩写是
return ![self checkForOverlap:gestureRecognizer];
)
这篇关于iOS:对象重叠时禁用平移手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文