2017-09-05 7 views
1

처음으로 크기를 조절하고 원래 크기로 회전하지 않고 크기를 회전시키는 UIView 애니메이션을 만드는 방법이 궁금합니다.스케일링과 같은 UIView 변환 시퀀스에 애니메이션을 적용하고 iOS에서 회전하는 방법은 무엇입니까?

UIView animateKeyframes 등을 사용하여 UIView 애니메이션 완성시 UIView 애니메이션을 배치하는 것과 같은 많은 방법을 시도했습니다.

그러나 애니메이션을 완벽하게 만들 수는 없으므로 힌트 또는 키워드를 검색해주세요. 감사합니다.

+1

수행 한 작업을 표시 할 수 있습니까? – Shebuka

+0

검색 할 키워드 : 'ios jiggle animation for uiview' – DonMag

+0

이 링크를 통해 가보 았습니까? - https://stackoverflow.com/questions/3703922/how-do-you-create-a-wiggle-animation-similar- 아이폰 삭제 애니메이션 https://stackoverflow.com/questions/929364/how-to-create-iphones-wobbling-icon-effect –

답변

0

귀하가 UIButton을 스케일링하거나 흔들면,이 코드는 UIView 애니메이션 시퀀스 반복 및 자동 되감기를하도록 안내합니다.

btn.frame = frame1; 
[UIView animateKeyframesWithDuration:2.0 delay:0.0 options:UIViewKeyframeAnimationOptionAutoreverse | UIViewKeyframeAnimationOptionRepeat animations:^{ 
    [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.5 animations:^{ 
     // Your changes to the UI, eg. scale UIButton up 300 points 
     btn.frame = frame2; 
    }]; 
    [UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.5 animations:^{ 
     // Your changes to the UI, eg. rotate or shake UIButton 
    }]; 
} completion:nil]; 
1

이 귀하의 요구 사항에 따라 작동합니다 (크기를 조정하는 방법에 첫 규모와 대신 원래 크기에서 회전의 크기를 회전 UIView의 애니메이션을 만들려면?)

@IBOutlet var scaleRotateImage: UIImageView! 
func scaleNTransform() -> Void { 

    scaleRotateImage.layer.cornerRadius = scaleRotateImage.frame.size.height/2.0 
    scaleRotateImage.clipsToBounds = true 

    let scaleTransform = CGAffineTransform(scaleX: 3.0, y: 3.0) // Scale 
    let rotateTransform = CGAffineTransform(rotationAngle: CGFloat.pi) // Rotation 
    let hybridTransform = scaleTransform.concatenating(rotateTransform) // Both Scale + Rotation 

    // Outer block of animation 
    UIView.animate(withDuration: 5.0, animations: { 
     self.scaleRotateImage.transform = scaleTransform 
     self.view.layoutIfNeeded() 
    }) { (isCompleted) in 

     // Nested block of animation 
     UIView.animate(withDuration: 5.0, animations: { 
      self.scaleRotateImage.transform = hybridTransform 
      self.view.layoutIfNeeded() 
     }) 

    } 


} 


결과

enter image description here

+0

이것은 내가 원하는 것처럼 보입니다. 나는 이런 식으로 만들려고 노력했지만, 세 개 이상을 연결할 수 있습니까? 나는 그것을 확대하고 흔들어주고 싶다. 감사! –

+0

요구 사항의 GIF를 공유 할 수 있습니까? (유튜브 비디오는 네트워크 제한 때문에 나에게 접근 할 수 없다.) 그래서 나는 당신을 더 잘 도울 수있다. – Krunal

+0

물론, 편집 해 주신 덕분에 많은 것을 ... –

2

당신이 할 수있는 ,

-(void)viewDidAppear:(BOOL)animated{ 

[super viewDidAppear:animated]; 

CGAffineTransform leftTransform = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-10.0)); 
CGAffineTransform rightTransform = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(10.0)); 

_myView.transform = leftTransform; //Here `_myView` is the your view on which you want animations! 

[UIView beginAnimations:@"youCanSetAnimationIdHere" context:(__bridge void * _Nullable)(_myView)]; 
[UIView setAnimationRepeatAutoreverses:YES]; 
[UIView setAnimationRepeatCount:5]; 
[UIView setAnimationDuration:0.25]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(animationCompletedWithAnimationId:isCompleted:view:)]; 

_myView.transform = rightTransform; 

[UIView commitAnimations]; 

} 

,

viewDidAppear에서 라디안 다음

#define RADIANS(degrees) (((degrees) * M_PI)/180.0) 

로도 변환 할 라디안 정의, 그런 짓을하고 animationCompletedWithAnimationId 방법은 같아야합니다

- (void) animationCompletedWithAnimationId:(NSString *)animationID isCompleted:(NSNumber *)isCompleted view:(UIView *)view 
{ 
if ([isCompleted boolValue]) { 
    UIView *myView = view; 
    myView.transform = CGAffineTransformIdentity; 

} 
} 

그리고 결과는

입니다.

enter image description here

요구 사항에 따라 반복 횟수와 라디안을 변경할 수 있습니다!

+0

순서대로 변형을 추가 할 수 있습니까? 스케일 된 크기를 사용하여 빌드 할 수 없습니다. 원래 크기로 돌아가서 회전합니다. –

+0

'_myView.transform = CGAffineTransformMakeScale (2, 2); '처럼 추가하려고합니다! – Lion

+0

나는 크기를 조정 한 다음 길을 사용하려고 시도했지만 원본 크기로 회전합니다 ... T T –