How to get Coordinates and PixelColor of TouchPoint in iOS/ObjectiveC

依然范特西╮ 提交于 2019-12-03 21:29:36
rdelmar

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 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!