我在我的superview中添加了一个Subview A(self.thumbnailImageView)。我已将UILongPressGestureRecognizer和UISwipeGestureRecognizer添加到我的子视图A.
-(void)tapGesture:(UILongPressGestureRecognizer *)recognizer{
if (recognizer.state == UIGestureRecognizerStateBegan)
{
// Long press detected, start the timer
[self showPreviewImage:recognizer];
}
else if(recognizer.state == UIGestureRecognizerStateEnded)
{
[self hidePreviewImage];
}
}
-(void)showPreviewImage:(UILongPressGestureRecognizer *)recognizer{
UIImageView *bigPreviewImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Desktop"]];
bigPreviewImage.frame = CGRectMake(self.thumbnailImageView.frame.origin.x - 50.0, self.thumbnailImageView.frame.origin.y + self.thumbnailImageView.frame.size.height + 10.0, 300.0, 250.0);
bigPreviewImage.tag = 10000;//200.0 & 125.0
[bigPreviewImage setUserInteractionEnabled:YES];
[self.view addSubview:bigPreviewImage];
}
现在在处理程序方法中,当UILongPressGestureRecognizer状态开始时,我将一个Subview B(bigPreviewImage)添加到我的superview(self.view)。
shouldRecognizeSimultaneouslyWithGestureRecognizer
现在,一旦UILongPressGestureRecognizer处于活动状态,用户仍然按下子视图A,如果用户向上滑动屏幕,我希望SwipeGestureRecognizer启动。但同样的事情并没有发生。如何在手势处于活动状态时启动手势识别器?
我已经实现了var logoImage = SKSpriteNode(imageNamed: "image1.png")
方法,但仍未调用向上滑动手势方法。如果我错过了什么,请告诉我。
答案 0 :(得分:0)
得到了!!!
我们不需要单独的滑动手势识别器。 Long Press Gesture Recognizer中的不同状态可用于处理此场景。
Long Press Gesture有不同的状态,如UIGestureRecognizerStateBegan
,UIGestureRecognizerStateChanged
和UIGestureRecognizerStateEnded
。
UIGestureRecognizerStateBegan
就会被调用。
UIGestureRecognizerStateChanged
被调用。
UIGestureRecognizerStateEnded
被调用。
-(void)longPressGestureForPreviewImageView:(UILongPressGestureRecognizer *)recognizer{
if (recognizer.state == UIGestureRecognizerStateBegan)
{
// Long press detected, start the timer
[self showPreviewImage:recognizer];
}
else if(recognizer.state == UIGestureRecognizerStateChanged)
{
NSLog(@"Swipe up");
if ([self.thumbnailImageView.gestureRecognizers containsObject:recognizer]) {
[self.thumbnailImageView removeGestureRecognizer:recognizer];
}
}
else if(recognizer.state == UIGestureRecognizerStateEnded)
{
[self hidePreviewImage];
}
因此我们可以使用Gesture Delegate方法来处理滑动以及Long Press手势识别器。