【问题标题】:Rotate button around center围绕中心旋转按钮
【发布时间】:2010-03-11 22:22:20
【问题描述】:

我正在寻找一种在 iPhone 应用程序中创建菜单的方法,该菜单允许按钮围绕中心点旋转。直观地说:按钮是行星,中心是太阳。

  • 这将允许用户围绕圆形路径“旋转”按钮。

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

我开始使用这段代码,这是我从 mahboudz 的帖子中找到的:

- (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

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

任何帮助将不胜感激。

【问题讨论】:

    标签: iphone animation rotation cabasicanimation


    【解决方案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)
    

    【讨论】:

    • 感谢您的回答。诚然,这是我第一次涉足动画领域,所以我还没有让任何东西正常工作。
    • 这是什么???这是一段无用的代码。您会提高重复帐户的比率吗?
    猜你喜欢
    • 2019-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多