Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XCode-图像上触摸事件的精确相对坐标-iOS_Ios_Objective C_Xcode - Fatal编程技术网

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

XCode-图像上触摸事件的精确相对坐标-iOS,ios,objective-c,xcode,Ios,Objective C,Xcode,我试图建立一个简单的照片裁剪实用程序,用户可以触摸并选择图片边界。我需要图像上的精确触摸坐标 当我使用 CGImageRef imageRef = [staticBG.image CGImage]; UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView:[self view]]; y3=location.y; x3=location.x; 坐标x3、y

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

当我使用

    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];
但坐标仍然不太匹配

请提供帮助。

使用以下代码:


我认为我们不需要用户触摸的精确坐标,但要裁剪图像,我将:

在图像上布局maskView,让用户选择要显示的区域 庄稼maskView有一个很容易知道的精确框架。 使用触摸开始和触摸移动检测用户触摸。虽然 用户触摸移动、移动maskView以及更改maskView的 框架在这一步中,我们需要确定 maskView是最接近用户触摸的点-leftTop, 右上、左下或右下。 在touchesEnded上,我们使用maskView的框架来显示。 这里的坐标足够精确。注意,我们需要改变 图像坐标系的maskView框架。
希望有帮助

但是如果你知道图像在视图中的位置,而y3和x3是视图中的触摸位置,你能简单地计算出相对坐标吗?或者我理解错了吗?是的,我试着做了什么,但最终的结果不匹配。我以为它会。。。但这让我失望:我同意,这是一种更成熟的方法。我想我迟早会按照你的方式去做。。。但我想说的是。。。难道没有任何可能的方法准确地找出接触点吗?注:我还考虑在图像上添加四个按钮来标记作物的四个角,并让用户沿这些按钮拖动。但首先,我需要看看我是否可以通过简单的接触点来做到这一点
- (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);

    }