gpt4 book ai didi

ios - XCode - 图像上触摸事件的精确相对坐标 - iOS

转载 作者:行者123 更新时间:2023-11-28 22:40:19 35 4
gpt4 key购买 nike

我正在尝试构建一个简单的照片裁剪实用程序,用户可以在其中触摸并选择图片边界。我需要图像的精确触摸坐标。

当我使用

    CGImageRef imageRef = [staticBG.image CGImage];
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[self view]];
y3=location.y;
x3=location.x;

坐标 (x3,y3) 以绝对比例出现,对处理 imageRef 没有用。

我试过用

    UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:staticBG];

但坐标仍然不完全匹配。

请帮忙。

最佳答案

使用以下代码:)

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [touches anyObject];

if ([touch tapCount] == 2) {
//self.imageView.image = nil;
return;
}

CGPoint lastPoint = [touch locationInView:self.YourImageView];
NSLog(@"%f",lastPoint.x);
NSLog(@"%f",lastPoint.y);

}

关于ios - XCode - 图像上触摸事件的精确相对坐标 - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14724467/

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