gpt4 book ai didi

iphone - 来自 UITapGestureRecognizer 的 CGPoint

转载 作者:可可西里 更新时间:2023-11-01 03:34:01 25 4
gpt4 key购买 nike

我需要获取 UITapGestureRecognizer 的 x 和 y 位置,但在这样做时我的应用程序崩溃了

这是我创建识别器的代码

-(void)imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *) info
{

[[picker parentViewController] dismissModalViewControllerAnimated:YES];

UIImage * image =[info objectForKey:@"UIImagePickerControllerOriginalImage"];

[image drawInRect:CGRectMake(0,0, 200, 400)];

MyImg =[[UIImageView alloc] initWithImage:image];

UITapGestureRecognizer *recognizer;

MyImg.userInteractionEnabled=YES;

recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(getTouchColor:)];
[MyImg addGestureRecognizer:recognizer];
[recognizer release];

[self.view addSubview:MyImg];

[picker release];

}

还有我的事件 GetTouchColor

-(void)getTouchColor:(UITapGestureRecognizer *) recognizer
{
if (recognizer.state==UIGestureRecognizerStateEnded)
{

CGPoint point = [recognizer locationInView:MyImg];

NSLog(@"%@", NSStringFromCGPoint(point));
}

如果我删除行

 CGPoint point = [recognizer locationInView:MyImg];

代码运行完美,应用程序不会崩溃。

我做错了什么?

谢谢

//对不起我的英语来自谷歌

最佳答案

检查 recognizer 不是 nil。向 nil 发送消息通常会返回 nil 或 0,这取决于返回类型,但是当它是一个结构返回类型时,结果是未定义的,并且可能(以及其他事情)导致崩溃。

关于iphone - 来自 UITapGestureRecognizer 的 CGPoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6810929/

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