如何在iOS / ObjectiveC中获取TouchPoint的坐标和PixelColor [英] How to get Coordinates and PixelColor of TouchPoint in iOS/ObjectiveC

查看:368
本文介绍了如何在iOS / ObjectiveC中获取TouchPoint的坐标和PixelColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Objective-C中获取TouchPoint的坐标和PixelColor。这是可能吗?如果是的话,我会非常感兴趣的方法或任何提示在正确的方向。 Thanx !!!

I need to get the Coordinates and PixelColor of a TouchPoint in Objective-C. Is this even possible? If yes I would be very interested in the how-to or any hint in the right direction. Thanx!!!

推荐答案

我得到的颜色下鼠标点击与UIView类别方法发布的ivanzoid =http://stackoverflow.com/questions/1160229/how-to-get-the-color-of-a-pixel-in-an-uiview>如何获取UIView中像素的颜色?)。我在自定义视图实现中使用它:

I get the color under the mouse click point with a UIView category method posted by ivanzoid (How to get the color of a pixel in an UIView?). I use it like this in a custom view implementation:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint loc = [touch locationInView:self];
    self.pickedColor = [self colorOfPoint:loc];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ColorPicked" object:self userInfo:nil];
}

colorOfPoint是ivazoid类别中获取颜色的方法,loc wil触摸点的坐标。我发布一个通知,以便我的视图控制器然后可以做这种颜色的东西。

colorOfPoint is the method in ivazoid's category that gets the color, and loc wil contain the coordinates of the touch point. I post a notification so that my view controller can then do something with this color.

这篇关于如何在iOS / ObjectiveC中获取TouchPoint的坐标和PixelColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆