我有一个视图,我想让用户在选项卡UIButton
之后进行绘制,我使用UIPanGestureRecognizer
执行此操作,在{{UIPanGestureRecognizer
之后添加UIButton
此视图1}}触摸,但问题是我完成绘图后重新触摸UIPanGestureRecognizer
??
UIButton
答案 0 :(得分:2)
UIView有一个名为
的方法- (void)removeGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
或者,您可以通过使用方法删除其回调来临时禁用UIGestureRecognizer
- (void)removeTarget:(id)target action:(SEL)action
答案 1 :(得分:0)
UIPanGestureRecognizer gestureRecognizer.cancelsTouchesInView = NO;
答案 2 :(得分:0)
如果视图有多个平移手势识别器,则可以使用关联对象标记特定的手势识别器。
What is objc_setAssociatedObject() and in what cases should it be used?
所以在.m文件的顶部,你会放
static char overviewKey;
然后在您将UIPanGestureRecognizer
添加到视图之前,您将使用字符串对其进行标记。
objc_setAssociatedObject(panGesture, &overviewKey, @"pan gesture for drawing", OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[someView addGestureRecognizer:panGesture];
如果要删除UIPanGestureRecognizer
,您需要浏览该视图中的所有手势识别器,找到带有该字符串的手势识别器,然后将其删除。
for (UIGestureRecognizer *gesture in someView) {
NSString *gestureTag= objc_getAssociatedObject(gesture, &overviewKey);
if (gestureTag==nil) {
continue;
}
if ([gestureTag isEqual:@"pan gesture for drawing"]) {
[ someView removeGestureRecognizer:gesture ];
}
}