简体   繁体   English

如何在iPhone SDK中以循环方式移动图像

[英]How to Move an image in circular in iPhone sdk

I have one image in circular format and i want to rotate in circular way when i touch it so can any one tell me what i have to do and give me some source code 我有一张圆形的图像,我想在触摸时以圆形方式旋转,所以任何人都可以告诉我该怎么做并提供一些源代码

thank to all,.. 谢谢大家,..

try something like this. 尝试这样的事情。

- (void)spinButton
{
    [CATransaction begin];
    [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
    CGRect frame = [button frame];
    button.layer.anchorPoint = CGPointMake(0.5, 0.5);
    button.layer.position = CGPointMake(frame.origin.x + 0.5 * frame.size.width, frame.origin.y + 0.5 * frame.size.height);
    [CATransaction commit];

    [CATransaction begin];
    [CATransaction setValue:(id)kCFBooleanFalse forKey:kCATransactionDisableActions];
    [CATransaction setValue:[NSNumber numberWithFloat:2.0] forKey:kCATransactionAnimationDuration];

    CABasicAnimation *animation;
    animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    animation.fromValue = [NSNumber numberWithFloat:0.0];
    animation.toValue = [NSNumber numberWithFloat:2 * M_PI];
    animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
    animation.delegate = self;
    [button.layer addAnimation:animation forKey:@"rotationAnimation"];

    [CATransaction commit];
}

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)finished
{
    if (finished)
    {
        [self spinButton];
    }
}

End the animation by calling something like 通过调用类似的方法结束动画

- (void)setButtonImage:(UIImage *)image
{
    [button.layer removeAllAnimations];
    if (!image)
    {
        [button setImage:[UIImage imageNamed:@"playbutton.png"] forState:0];
    }
    else
    {
        [button setImage:image forState:0];

        if ([button.currentImage isEqual:[UIImage imageNamed:@"loadingbutton.png"]])
        {
            [self spinButton];
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM