2011-03-03 169 views
1

我做了一个应用程序,它设置了睡眠定时器的时钟。基本上它是单手时钟,用户可以移动以设置他的睡眠时间。我试图旋转图像uitouch但它从中间旋转,但我希望它从tip.Secondly旋转。其次,我希望该图像只旋转时,用户正在触摸图像的提示,但在我的项目中,图像也旋转时使用触摸任何部分的screen.Also我想在两个方向上旋转图像,但在我的项目是由于这种方法旋转图像

image.transform = CGAffineTransformRotate(image.transform, degreesToRadians(1));

只移动顺时针

任何人都可以给我提示或解决方案,如何做到这一点?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
    // 

     touch = [[event allTouches] anyObject]; 
     touchLocation = [touch locationInView:touch.view]; 

     NSLog(@"began"); 

    } 


    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
     // get touch event 

     [image.layer setAnchorPoint:CGPointMake(0.0,0.0)]; 



     if ([touch view] == image) { 
      image.transform = CGAffineTransformRotate(image.transform, degreesToRadians(1)); 

     //image.center = touchLocation; 
    } 

     } 

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ 
     NSLog(@"end"); 



    } 

回答

0

要旋转它,你只需要使用其他方法:

image.transform = CGAffineTransformRotate(image.transform, degreesToRadians(1)); 

而旋转形成你应该使用setAnchorPoint(就像你在你的代码中使用的提示,但我认为你应该做的:[图像setAnchorPoint] )。

更多关于这个问题:setAnchorPoint for UIImage?

+0

你能解释一下这个过程吗?我从代码中不太明白它,你如何设置所有东西来旋转视图? – 8vius 2011-06-27 20:02:57

0

我试着旋转与uitouch的形象,但它从中间旋转,但我希望它从顶端

我不知道在SDK的任何方式来旋转元素旋转在其极端。如果你想得到这个效果,你可以使用时钟手柄图像,你有两倍的长度和半透明的部分。这不是一个直接的解决方案,而是一种解决方法。

此外,我想在两个方向,但在我的项目将图像旋转它只能移动顺时针由于这种方法

按照iOS的开发者文档,正角度值指定逆时针旋转和负值指定顺时针旋转。

2

详细,你可以自定义一个rotateView,则:

1:在 “的touchesBegan” 的委托方法,让手指和initialAngle的initialPoint。

2:在 “touchesMoved”,得到newPoint手指:

CGPoint newPoint = [[touches anyObject] locationInView:self]; 
[self pushTouchPoint:thePoint date:[NSDate date]]; 
double angleDif = [self angleForPoint:newPoint] - [self angleForPoint:initialPoint]; 
self.angle = initialAngle + angleDif; 
[[imageView layer] setTransform:CATransform3DMakeRotation(angle, 0, 0, 1)]; 

3:最后,在 “touchesEnded” 就可以计算出最终AngularVelocity。

如果有什么困惑,更详细的信息,你可以回信。