【发布时间】:2012-05-22 22:35:32
【问题描述】:
我需要在 Objective-C 中获取 TouchPoint 的坐标和像素颜色。这甚至可能吗?如果是的话,我会对正确方向的操作方法或任何提示非常感兴趣。谢谢!!!
【问题讨论】:
标签: objective-c ios colors touch coordinates
我需要在 Objective-C 中获取 TouchPoint 的坐标和像素颜色。这甚至可能吗?如果是的话,我会对正确方向的操作方法或任何提示非常感兴趣。谢谢!!!
【问题讨论】:
标签: objective-c ios colors touch coordinates
我使用 ivanzoid (How to get the color of a pixel in an UIView?) 发布的 UIView 类别方法获取鼠标单击点下的颜色。我在自定义视图实现中这样使用它:
- (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 将包含触摸点的坐标。我发布了一条通知,以便我的视图控制器可以用这种颜色做一些事情。
【讨论】: