gpt4 book ai didi

objective-c - 点击手势事件未在UIImageView上触发

转载 作者:行者123 更新时间:2023-12-01 17:59:31 25 4
gpt4 key购买 nike

我正在尝试在UIImageView上实现敲打手势识别器。但是我无法处理触发tap事件的方法。我已经将我的代码与许多关于stackoverflow的类似问题的答案进行了比较,但是问题仍然存在。以下是我的应用程序中的相关代码。有人可以告诉我我做错了什么吗?

ViewController.h

IBOutlet UIImageView *topLeftImage;

-(IBAction)handleSingleTap:(UITapGestureRecognizer*)gestureView;

ViewController.m
- (void)viewDidUnload
{
[super viewDidUnload];

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
topLeftImage.userInteractionEnabled = YES;
[topLeftImage addGestureRecognizer:singleTap];

}

- (void)handleSingleTap:(UITapGestureRecognizer *)gestureRecognizer {

NSLog(@"Tap detected. Booyah!");
}

最佳答案

试试这个吧。您将代码放在viewDidUnload中,完全放在错误的位置。您需要viewDidLoad。

- (void)viewDidLoad
{
[super viewDidLoad];

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
topLeftImage.userInteractionEnabled = YES;
[topLeftImage addGestureRecognizer:singleTap];

}

关于objective-c - 点击手势事件未在UIImageView上触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12468684/

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