当我的hitView在UIPanGestureRecognizer之后部分来自superview时,UILongPressGestureRecognizer不起作用。为什么呢?
- (id)initWithFrame:(CGRect)frame
{
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[panGesture setMaximumNumberOfTouches:1];
[panGesture setDelegate:self];
[_glassesImage addGestureRecognizer:panGesture];
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(enchance:)];
longPressGesture.minimumPressDuration = 0.2;
[_glassesImage addGestureRecognizer:longPressGesture];
[self addSubview:_glassesImage];
}
- (void)enchance:(UILongPressGestureRecognizer *)gestureRecognizer
{
UIView *hitView = [gestureRecognizer view];
hitView.alpha=0.6;
inLongPress=YES;
gestureRecognizer.allowableMovement = 200;
if ([gestureRecognizer state] == UIGestureRecognizerStateEnded){
hitView.alpha=1.0;
inLongPress=NO;
}
}
答案 0 :(得分:1)
尝试为手势识别器定义委托,然后提供以下实现:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
(refs)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}
答案 1 :(得分:0)
将委托添加到longPressGesture。
longPressGesture.delegate = self;
我认为这会对你有所帮助。