iOS動畫入門一,iOS動畫入門
一 動畫介紹
在iOS中動畫實現技術主要是:Core Animation。 Core Animation負責所有的滾動、旋轉、縮小和放大以及所有的iOS動畫效果。其中UIKit類通常都有animated:參數部分,它可以允許是否使用動畫。
本文將介紹UIView動畫的實現方式,有基礎方法和block方法。
二 實現方法1 基礎動畫
[UIView beginAnimations:nil context:nil]; //動畫開始 //Code... [UIView commitAnimations]; //動畫結束
//eg 設定lb向下移動 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:3]; CGPoint point = self.lb.center; point.y += 100; self.lb.center = point; [UIView commitAnimations];
2 blcok方法1
[UIView animateWithDuration:3 //動畫期間 animations:^{ //Code... }];
//eg 改變lb的透明度 [UIView animateWithDuration:3 animations:^{ self.lb.alpha = 0.5; }];
3 blcok方法2
UIView animateWithDuration:3 //動畫期間 animations:^{ //動畫執行 } completion:^(BOOL finished) { //動畫完成後執行 }];
//eg 旋轉lb第一種方法: CGAffineTransform endAngel = CGAffineTransformMakeRotation(90.0f*(M_PI/180.0f)); [UIView animateWithDuration:3 animations:^{ self.lb.transform = endAngel; } completion:^(BOOL finished) { self.stateLb.text = @"動畫完成了"; }];
4 blcok方法3
[UIView animateWithDuration:3 //動畫期間 delay:1 //動畫延遲時間 options:UIViewAnimationOptionCurveEaseIn //設定動畫過渡效果 animations:^{ //動畫執行 } completion:^(BOOL finished) { //動畫完成後執行 }];
//eg 改變lb的字型大小 和位置 [UIView animateWithDuration:3 delay:1 options:UIViewAnimationOptionCurveEaseInOut //設定動畫過渡效果 animations:^{ CGPoint center = self.lb.center; center.x = 200; self.lb.center = center; self.lb.textColor = [UIColor blueColor]; } completion:^(BOOL finished) { self.stateLb.text = @"改變lb的字型大小 和位置 完成*"; }];
5 blcok方法4
[UIView animateWithDuration:3 //動畫期間 delay:1 //動畫延遲時間 usingSpringWithDamping:1.0 //設定類似彈簧效果 initialSpringVelocity:5.0 //設定初始速度 options:UIViewAnimationOptionCurveLinear //設定動畫過渡效果 animations:^{ } completion:^(BOOL finished) { }];
[UIView animateWithDuration:3 delay:1 usingSpringWithDamping:1.0 initialSpringVelocity:5.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ CGPoint center = self.btn.center; center.y += 50; self.btn.center = center; } completion:^(BOOL finished) { self.stateLb.text = @"彈簧效果結束"; }];
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。