headkit
headkit

Reputation: 3327

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

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

Upvotes: 1

Views: 3866

Answers (1)

rdelmar
rdelmar

Reputation: 104082

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.

Upvotes: 2

Related Questions