2013-12-12 3 views
0

문을 여는 것처럼 화면의 오른쪽 가장자리를 회전 시키려합니다. 이것은 내가 지금까지 무엇을 가지고 : 누군가가 올바른 방향으로 날 밀어 수 있다면, 그래서화면의 오른쪽 주위에 UIView를 회전하십시오.

CATransform3D transform = CATransform3DIdentity; 
transform.m34 = -1.0f/500; 
view.layer.transform = CATransform3DRotate(transform, kDegreesToRadians(90), 0, 1, 0); 
[UIView animateWithDuration:2.0f animations:^{ 
    view.layer.transform = transform; 
} completion:nil]; 

나는 그 문제에 대해 아직 또는 행렬 CATranforms에 완전히 고체 아니에요, 그것은 많이 감사 할 것입니다!

+0

앵커 포인트를 변경하려고 시도 했습니까? http://stackoverflow.com/questions/7438385/ios-rotate-view-around-an-anchor-point-and-follow-touch – atxe

답변

2

UIView 애니메이션은 레이어의 애니메이션이 아닌보기 속성에 애니메이션을 적용하기위한 것입니다. 필자가 아는 한, UIView animateWithDuration : 호출을 사용하여 뷰의 레이어를 애니메이션으로 만들 수는 없습니다.

CABasicAnimation을 만들고보기 레이어에 직접 추가해야합니다. 그래서, 당신은이 애니메이션을하기 전에, 1 .5 레이어의 기준점을 이동해야

을 atxe가 말하기를 :

은 내가 CAAnimations을 수행 한 이후 오랜만 만의 내가 발굴 할 수 있는지 보자 있어요 오른쪽 가장자리를 중심으로 회전합니다.

//Open the door. 
rotateAnimation = [CABasicAnimation animation]; 
rotateAnimation.keyPath = @"transform"; 
rotateAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity]; 

//Pivot on the right edge (y axis rotation) 
theTransform = CATransform3DIdentity; 
    theTransform.m34 = -1/100.0; 
    theTransform = CATransform3DRotate(theTransform, degreesToRadians(70), 0, 1, 0); 


rotateAnimation.toValue = [NSValue valueWithCATransform3D:theTransform]; 

rotateAnimation.duration = 0.5; 

// leaves presentation layer in final state; preventing snap-back to original state 
rotateAnimation.removedOnCompletion = NO; 
rotateAnimation.fillMode = kCAFillModeBoth; 

rotateAnimation.repeatCount = 0; 
rotateAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
rotateAnimation.delegate = self; 
[treeDoorImageView.layer addAnimation:rotateAnimation forKey:@"transform"]; 

논리를 변환은 당신에 대한 모든하지만 동일입니다 (제가 사용 : 여기

는 문 애니메이션은 그것의 경첩에 열려 스윙 않는 우리의 "케빈 & 켈"만화 앱에서 일부 코드 +1/100의 m34 값을 사용하면 과장된 3D 효과를 얻을 수 있습니다.

UIView 애니메이션 블록에서 애니메이션을 재생하는 대신 CABasicAnimation을 만들고, fromValue 및 toValue 속성을 시작 및 끝 변환 값으로 설정합니다.

이 코드를 애니메이션의 시작점으로 사용할 수 있어야합니다.

+0

환상적인 답변입니다. 감사! – barndog

0

UIView 블록 애니메이션이 아닌 CAAnimation을 사용해야합니다. 지적 또한

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"]; 
animation.duration = 2; 
animation.fromValue = [NSValue valueWithCATransform3D:view.layer.transform]; // From the existing transform. 
animation.toValue = [NSValue valueWithCATransform3D:transform]; // To the new one. 

view.layer.transform = transform; // Set the new transform. 
[view.layer addAnimation:animation forKey:@"door"]; // Animate visual change. 

, axte , 당신은 레이어의 오른쪽 가장자리 주위에 회전을 적용 (1, 0.5)에 레이어의 anchorPoint을 설정해야합니다.

관련 문제