2010-03-11 225 views
0

我正在寻找一种方法来在iPhone应用程序中创建一个允许按钮围绕中心点旋转的菜单。把它放在视觉上:按钮是行星,中心是太阳。围绕中心旋转按钮

  • 这将允许用户'旋转'圆形路径周围的按钮。

**一个实际的例子就是他们iPhone应用程序的Poynt菜单。 **

我开始使用此代码,我从后发现mahboudz这里SO:

- (void) runSpinAnimationWithDuration:(UIView*)animatedView withDuration:(CGFloat) duration; 
{ 
CABasicAnimation* rotationAnimation; 
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"]; 
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * 1 * duration ]; 
rotationAnimation.duration = duration; 
rotationAnimation.cumulative = YES; 
rotationAnimation.repeatCount = 1.0; 
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 
[animatedView.layer setAnchorPoint:CGPointMake(0.5, 0.5)]; 
[animatedView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; 
} 

有上旋转了一个有趣的帖子在这里对这样:link text

无论如何,我可以旋转一个按钮 - 但不是围绕预定路径(如行星场景)。

任何帮助,将不胜感激。

回答

-1

您正在围绕它自己的中心旋转按钮,如“frame”属性所定义。此外,您还需要在旋转按钮的同时将按钮的框架更改为不同的坐标。类似这样的:

CGFloat angle = rotationAnimation.toValue; 
CGFloat radius = 50; 
CGPoint rotationCenter = CGPointMake(100,100); 
b.frame = CGRectMake(rotationCenter.x + radius * cos(angle), rotationCenter.y + radius * sin(angle), b.frame.size.width, b.frame.size.height) 
+0

感谢您的回答。无可否认,这是我第一次进入动画领域,因此我还没有得到任何正确的工作。 – CraigH 2010-03-12 16:45:54

+0

这是什么?这是无用的一段代码。你是否提高重复账户的利率? – 2015-08-31 08:57:33