2011-12-13 68 views
-2
[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]; 

我想这码BT没有用,我想移动图像视图在圆形路径图像视图

回答

1

你想要可以不使用CAAnimation类完成的动画。

使用的NSTimer对象内部下面的代码..

做一个循环内该角变量是从0开始到无穷大或360°

//半径倍数是圆的半径,其中你想移动ImageView。

myImageView.center = CGPointMake(myImageView.center.x + cos(angle) * radius, myImageView.center.y + sin (angle) * radius); 
+0

BT上面的代码将通过其中心旋转图像视图,W想要的图像以沿任意点 – Amrut

+0

HI阿尼尔旋转,我需要图像视图不断朝这个方向移动 – Amrut

2

请检查移动图像的代码...感谢

UIBezierPath *customPath =[self createArcPath]; 

    UIImage *movingImage = [UIImage imageNamed:@"Unchecked.png"]; 
    CALayer *movingLayer = [CALayer layer]; 
    movingLayer.contents = (id)movingImage.CGImage; 
    movingLayer.anchorPoint = CGPointZero; 
    movingLayer.frame = CGRectMake(0.0f, 0.0f, movingImage.size.width, movingImage.size.height); // image position starting 
    [self.view.layer addSublayer:movingLayer]; 

    CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
    pathAnimation.duration = 4.0f; 
    pathAnimation.path = customPath.CGPath; 
    pathAnimation.calculationMode = kCAAnimationLinear; 
    [movingLayer addAnimation:pathAnimation forKey:@"movingAnimation"]; 

} 
    - (UIBezierPath *)createArcPath 
    { 
     UIBezierPath *aPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) 
                  radius:10 
                 startAngle:0 
                  endAngle:2* M_PI 
                  clockwise:YES]; 
     return aPath; 
    }