我想在圆圈内点击时找到该区域。其实我已经做了一个计算,但那是不准确的。
检查我编写的代码片段,以便在我的循环视图中找到选项卡的位置。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event" this method
float dx = touchLocation.x -160;
float dy = touchLocation.y - 240;
double angle = atan2(touchLocation.x,touchLocation.y);
/* Device is iPad */
if (count==4) {
if(angle>-1.639&&angle<=0.775)
{
area=1;
NSLog(@"touched here 1 ********************************** ");
}
else if(angle>0.775&&angle<=1.579)
{
area=2;
NSLog(@"touched here 2********************************** ");
}
else if(angle>1.579&&angle<=2.466)
{
area=3;NSLog(@"touched here 3********************************** ");
}
else
{
area=4;NSLog(@"touched here 4 ********************************** ");
}
}
else if (count==5) {
if(angle>-1.520&&angle<=0.553)
{
area=1;
NSLog(@"touched here 1 ********************************** ");
}
else if(angle>0.553&&angle<=1.262)
{
area=2;
NSLog(@"touched here 2********************************** ");
}
else if(angle>1.262&&angle<=1.884)
{
area=3;NSLog(@"touched here 3********************************** ");
}
else if(angle>1.884&&angle<=2.644)
{
area=4;NSLog(@"touched here 4 ********************************** ");
}
else
{
area=5;NSLog(@"touched here 5 ********************************** ");
}
}
else if (count==6) {
if(angle>-1.5707&&angle<=0.4692)
{
area=1;
NSLog(@"touched here 1 ********************************** ");
}
else if(angle>0.4692&&angle<=1.0219)
{
area=2;
NSLog(@"touched here 2********************************** ");
}
else if(angle>1.0219&&angle<=1.5707)
{
area=3;NSLog(@"touched here 3********************************** ");
}
else if(angle>1.5707&&angle<=2.1147)
{
area=4;NSLog(@"touched here 4 ********************************** ");
}
else if(angle>2.1147&&angle<=2.7245)
{
area=5;NSLog(@"touched here 5 ********************************** ");
}
else
{
area=6;NSLog(@"touched here 6 ********************************** ");
}
}
else if (count==7) {
if(angle>-1.5707&&angle<=0.3992)
{
area=1;
NSLog(@"touched here 1 ********************************** ");
}
else if(angle>0.3992&&angle<=0.8602)
{
area=2;
NSLog(@"touched here 2********************************** ");
}
else if(angle>0.8602&&angle<=1.346)
{
area=3;NSLog(@"touched here 3********************************** ");
}
else if(angle>1.346&&angle<=1.812)
{
area=4;NSLog(@"touched here 4 ********************************** ");
}
else if(angle>1.812&&angle<=2.304)
{
area=5;NSLog(@"touched here 5 ********************************** ");
}
else if(angle>2.304&&angle<=2.828)
{
area=6;NSLog(@"touched here 6 ********************************** ");
}
else
{
area=7;NSLog(@"touched here 7 ********************************** ");
}
}
else if (count==8){
if(angle>-1.40&&angle<=0.45)
{
area=1;
NSLog(@"touched here 1 ********************************** ");
}
else if(angle>.45&&angle<=.73)
{
area=2;
NSLog(@"touched here 2********************************** ");
}
else if(angle>.73&&angle<=1.15)
{
area=3;NSLog(@"touched here 3********************************** ");
}
else if(angle>1.15&&angle<=1.55){
area=4;NSLog(@"touched here 4 ********************************** ");
}
else if(angle>-1.55&&angle<=1.95){
area=5;NSLog(@"touched here 5 ********************************** ");
}
else if(angle>-1.95&&angle<=2.43){
area=6;NSLog(@"touched here 6 ********************************** ");
}
else if(angle>2.43&&angle<=2.98){
area=7;NSLog(@"touched here 7********************************** ");
}
// else if(angle>2.98&&angle<=-1.40){
else
{
area=8;NSLog(@"touched here 8 ********************************** ");
}
}