2017-04-06 7 views
0

x 축에서 180도 회전해야합니다. 회전은 끝났지 만 회전이 시작되면 반쪽이 접 힙니다. 이것은 제가 한 코드가 도움이 될 수 있습니다.CABasicAnimation x 축에서 뷰 회전

 CABasicAnimation* rotationAnimation; 
     rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"]; 
     rotationAnimation.fromValue = [NSNumber numberWithFloat:0]; 
     rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0]; 
     rotationAnimation.duration = 2.0; 
     rotationAnimation.cumulative = YES; 
     rotationAnimation.repeatCount = 0; 
     [_view_topShowDate.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; 
+0

당신이 접힌 뷰의 이미지를 게시하시기 바랍니다 수 아래의 사용 위치를 변경하려면? – shallowThought

+0

[CABasicAnimation을 사용하여 UIImageView를 두 번 이상 회전] 가능한 복제본 (http://stackoverflow.com/questions/17426802/using-cabasicanimation-to-rotate-a-uiimageview-more-than-once) –

답변

0

앵커 포인트는 viewDidLoad 또는 애니메이션 시작 전에 어딘가에 설정해야합니다. 기본적으로 anchorPoint를 (0.5,0.5)로 취하므로 중심에서 회전을 보게됩니다.

_viewToRotate.layer.anchorPoint = CGPointMake(0.5, 1.0); 

그런 다음 기본 애니메이션 방법을 호출하십시오.

읽기는

당신이 앵커 지점을 변경하는 동안 http://ronnqvi.st/about-the-anchorpoint/에, 그것은 레이어의 위치를 ​​이동 더. 은의

-(void)setNewAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view 
{ 
    CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x, view.bounds.size.height * anchorPoint.y); 
    CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x, view.bounds.size.height * view.layer.anchorPoint.y); 

    newPoint = CGPointApplyAffineTransform(newPoint, view.transform); 
    oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform); 

    CGPoint position = view.layer.position; 

    position.x -= oldPoint.x; 
    position.x += newPoint.x; 

    position.y -= oldPoint.y; 
    position.y += newPoint.y; 

    view.layer.position = position; 
    view.layer.anchorPoint = anchorPoint; 
} 
관련 문제