我需要在 Objective-C 中获取 TouchPoint 的坐标和像素颜色。这可能吗?如果是,我会对正确方向的操作方法或任何提示非常感兴趣。谢谢!!!
最佳答案
我使用 ivanzoid ( How to get the color of a pixel in an UIView? ) 发布的 UIView 类别方法获取鼠标点击点下的颜色。我在自定义 View 实现中这样使用它:
- (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包含触摸点的坐标。我发布了一个通知,以便我的 View Controller 可以用这种颜色做一些事情。
关于objective-c - 如何在 iOS/Objective C 中获取 TouchPoint 的坐标和像素颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10711107/