我想在iOS中创建一个数字彩虹计。我想得到用户的反应,根据用户触摸彩虹在ios屏幕。
数字彩虹仪是一种VIBGYOR(声光、靛蓝、蓝、绿、黄、橙、红)梯度图像,是一种景观图像。如果用户接触到紫罗兰色带,我应该能够得到文字形式的颜色。然后,我必须将颜色信息传递给MySQL数据库,这部分是我通过使用php服务完成的。
但我无法获得用户触摸图像的颜色。请帮帮忙。
发布于 2014-09-30 14:49:17
如果你把屏幕分成七条,你可以通过检查每条边框的位置来绘制它们的地图。然后,如果覆盖touchesBegan,则可以执行所需的操作。
假设彩虹是由水平条组成的,则touchesBegan方法将如下所示:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint touchLocation = [[[event allTouches] anyObject] locationInView:touchView];
if (touchLocation.y < violetDownBorder && touchLocation.y > violetUpBorder) {
//Violet detected
//... send @"Violet" string to wherever
}else if (touchLocation.y < indigoDownBorder && touchLocation.y > indigoUpBorder){
//....
//Complete all colours (cases) here.
//....
}
}其中xxxxDownBorder和xxxxUpBorder是以像素为单位放置xxxx边框的垂直位置。
https://stackoverflow.com/questions/26121556
复制相似问题