gpt4 book ai didi

ios - UIImageView Tap Gesture 在第二次点击时不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:55:12 26 4
gpt4 key购买 nike

我已经在 UIImageView 上实现了 UITapGestureRecognizer,它正在处理第一次点击。在第一次点击时,我隐藏该图像并开始动画。动画完成后,我将再次显示图像。但是,我第二次没有收到该 UIImageView 的 Tap 事件。

以下是我使用的代码:

- (void)viewDidLoad{

[super viewDidLoad];

defaultDogView= [[UIImageView alloc] initWithFrame:CGRectMake(3, 270, 110, 210)];
[defaultDogView setImage:[UIImage imageNamed:@"dog1.png"]];
defaultDogView.userInteractionEnabled = YES;
[self addGestureRecognizersToPiece:defaultDogView];
[self.view addSubview:defaultDogView];

}

- (void)addGestureRecognizersToPiece:(UIImageView *)piece
{
NSLog(@"in Gesture");
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapPiece:)];
[tapGesture setDelegate:self];

[piece addGestureRecognizer:tapGesture];
[tapGesture release];

UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressPiece:)];
[piece addGestureRecognizer:longPressGesture];
[longPressGesture release];

NSLog(@"%@", [piece gestureRecognizers]);

}
- (void)singleTapPiece:(UITapGestureRecognizer *)gestureRecognizer
{
NSLog(@"Image Tapped");

/** Hide the default Image and start the animation ***/

[defaultDogView setHidden:TRUE];

/***Animating the Dog***/
[dogArray addObject:[SpriteHelpers setupAnimatedDog:self.view numFrames:69 withFilePrefix:@"dog" withDuration:(12) ofType:@"png" withValue:0]];
dogView = [dogArray objectAtIndex:0];

[self performSelector:@selector(callBubbleUpdater) withObject:nil afterDelay:5.5];
}
-(void)showDogFrame{
NSLog(@"%@",[defaultDogView gestureRecognizers]);
[defaultDogView setHidden:FALSE];
defaultDogView.userInteractionEnabled = YES;
}

最佳答案

找到错误。这是因为我的动画 View 重叠在 UIImageView 上。动画完成后我唯一需要做的就是让我的 UIImageView zindex 为 0。我使用以下代码解决了这个问题:

//animation stuff

//after animation complition
[self.view bringSubviewToFront:bubbleAlphabetView];

关于ios - UIImageView Tap Gesture 在第二次点击时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7820448/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com