2014-03-14 3 views
20

UIView 및 해당 내용의 크기를 조절하는 애니메이션을 만들고 싶습니다. 기본적으로 뷰를 먼저 확장 한 다음 다시 원래 크기로 축소하는 애니메이션을 만들고 싶습니다.UIView를 확장 및 축소하는 애니메이션 만들기

가장 좋은 방법은 무엇입니까? 나는 CALayer.contentScale을 시도했지만 전혀 아무것도하지 않았다.

+0

http://stackoverflow.com/questions/5446899/scale-zoom-into-a-uiview-at-a-point 또는 http://stackoverflow.com/questions/18329286/how-to-scale에 관련 -zoom-a-uiview-to-a-given-cgpoint? lq = 1? – tophyr

답변

44

둥지 할 수 있습니다 함께 그래서 같은 일부 애니메이션 블록 :

목표 - C :

[UIView animateWithDuration:1 
       animations:^{ 
        yourView.transform = CGAffineTransformMakeScale(1.5, 1.5); 
       } 
       completion:^(BOOL finished) { 
        [UIView animateWithDuration:1 
             animations:^{ 
              yourView.transform = CGAffineTransformIdentity; 

             }]; 
       }]; 

스위프트 2.0 :

UIView.animateWithDuration(1, animations: {() -> Void in 
    yourView.transform = CGAffineTransformMakeScale(1.5, 1.5) 
    }) { (finished: Bool) -> Void in 
     UIView.animateWithDuration(1, animations: {() -> Void in 
      yourView.transform = CGAffineTransformIdentity 
     })} 

스위프트 3.0 :

UIView.animate(withDuration: 1, animations: { 
    yourView.transform = CGAffineTransform(scaleX: 1.5, y: 1.5) 
}) { (finished) in 
    UIView.animate(withDuration: 1, animations: { 
     yourView.transform = CGAffineTransform.identity 
    }) 
} 

및 대체 s 자신 만의 가치와 기간을 창출하십시오.

8

여기 또한 루프 작은 방법입니다 :

[UIView animateWithDuration:1 
         delay:0 
        options:UIViewKeyframeAnimationOptionAutoreverse | UIViewKeyframeAnimationOptionRepeat 
       animations:^{ 
        yourView.transform = CGAffineTransformMakeScale(1.5, 1.5); 
       } 
       completion:nil]; 

옵션 UIViewKeyframeAnimationOptionRepeat 당신이 그것을 "호흡"을 유지하지 않으려면, 그것을 루프를 만드는 것입니다. 애니메이션 블록은 "흡입"기능을하며 UIViewKeyframeAnimationOptionAutoreverse 옵션은 자동으로 "내뿜기"애니메이션을 재생합니다.