自己做的一个围绕中心旋转的动画效果

 

 

       最近iphone需求要做到一些动画,想让一个图片围绕frame外的一个中心点进行旋转,但无论用center还是用anchorPoint,都要不到我想要的效果,只能采用此“小手段”来实现。如果有人有更好的实现方式,欢迎留言、评论、拍砖!

 

@begin

 

 

    UIView *bgVw = [[UIView alloc] initWithFrame:CGRectMake(0, 30, 300, 300)];
    bgVw.backgroundColor = [UIColor clearColor];
    
    UIView *centerVw = [[UIView alloc] initWithFrame:CGRectMake(100, 130, 100, 100)];
    centerVw.backgroundColor = [UIColor blueColor];
    [self.view addSubview:centerVw];
    
    UIView *vw = [[UIView alloc] initWithFrame:CGRectMake(0, 125, 50, 50)];
    vw.backgroundColor = [UIColor brownColor];
    
    UIView *vw2 = [[UIView alloc] initWithFrame:CGRectMake(250, 125, 50, 50)];
    vw2.backgroundColor = [UIColor redColor];
    
    UIView *vw3 = [[UIView alloc] initWithFrame:CGRectMake(125, 0, 50, 50)];
    vw3.backgroundColor = [UIColor orangeColor];
    
    UIView *vw4 = [[UIView alloc] initWithFrame:CGRectMake(125, 250, 50, 50)];
    vw4.backgroundColor = [UIColor greenColor];
    
    [bgVw addSubview:vw];
    [bgVw addSubview:vw2];
    [bgVw addSubview:vw3];
    [bgVw addSubview:vw4];
    [self.view addSubview:bgVw];
    
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0f];
    [UIView setAnimationRepeatAutoreverses:YES];
    [UIView setAnimationRepeatCount:10];
    bgVw.layer.anchorPoint = CGPointMake(0.5, 0.5);
    bgVw.transform = CGAffineTransformMakeRotation([self radians:-180]);
    
    [UIView commitAnimations];

 

 

 

@end

你可能感兴趣的:(iphone)