2017-09-05 4 views
1

最初にサイズを変更し、元のサイズで回転させる代わりにそのサイズを回転させるUIViewアニメーションを作成する方法はありますか?iOSでスケーリングしてから回転するようなUIViewトランスフォームシーケンスをアニメーション化する方法は?

私は、UIViewアニメーションの完成時にUIView animateKeyframesなどを使用して、UIViewアニメーションをラップするような方法を試してきました。

しかし、私は完璧なようなアニメーションを構築することはできません、ヒントやキーワードを検索してください、ありがとう!

+1

あなたは何をしましたか? – Shebuka

+0

検索するキーワード:「ios jiggle animation for uiview」 – DonMag

+0

このリンクを通過しましたか: https://stackoverflow.com/questions/3703922/how-do-you-create-a-wiggle-animation-similar- iPhoneの削除 - アニメーション 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

これはあなたの条件に応じて動作します(どのサイズに第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

これは私が欲しいものだと思われる、私はこのように構築しようとしましたが、私は3つ以上を連結することはできますか?私はそれを拡大縮小して振りたい。ありがとう! –

+0

要件のGIFを共有できますか? (YouTubeのビデオは私にはアクセスできません - ネットワークの制約のため)、私はあなたを助けることができます。 – 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; 

} 
} 

そして、結果は

です

要件に応じて繰り返し数とラジアンを変更できます。

+0

それは連続してスケールの変換を追加できますか?スケールされたサイズを使って構築することはできません。それは元のサイズに戻って回転します。 –

+0

'_myView.transform = CGAffineTransformMakeScale(2、2);'のように追加しようとします! – Lion

+0

私は縮尺を変えようとしましたが、元のサイズに回転しています... T T –

関連する問題