1.基本動畫方法介紹及使用
基本UIView Animation方法介紹
/**????????????????????????????????動畫配置????????????????????????????????**/
// default = nil. 默認為nil
+ (void)setAnimationDelegate:(nullable id)delegate;
// default = NULL. 需要設置(??)delegate
+ (void)setAnimationWillStartSelector:(nullable SEL)selector;
// default = NULL. 需要設置(??)delegate
+ (void)setAnimationDidStopSelector:(nullable SEL)selector;
// default = NULL. 需要設置(??)delegate
+ (void)setAnimationDuration:(NSTimeInterval)duration;
// default = 0.0. 延時動畫時間
+ (void)setAnimationDelay:(NSTimeInterval)delay;
// default = now. 設置某個時間點觸發(fā)(默認當前時間點)
+ (void)setAnimationStartDate:(NSDate *)startDate;
// default = UIViewAnimationCurveEaseInOut
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve;
// default = 0.0. 重復動畫次數(shù)
+ (void)setAnimationRepeatCount:(float)repeatCount;
/**??????????????????????????????????????????????????????????????????????**/
動畫控制的枚舉(UIViewAnimationCurve)
/********************動畫控制的枚舉(UIViewAnimationCurve)***************************/
UIViewAnimationCurveEaseInOut ;//漸入搔预,漸出
UIViewAnimationCurveEaseIn ;//漸入
UIViewAnimationCurveEaseOut ;//監(jiān)測
UIViewAnimationCurveLinear ;//
/*********************************************************************************/
- 使用方式一:最基本使用方式
//1.動畫方式一:
[UIView beginAnimations:@"animationID" context:nil]; //1.開始動畫 ????????(開始主要點)
[UIView setAnimationDuration:2];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
/************************3.動畫屬性方式等配置******************************/
CGRect frame = bigImage.frame;
if (isSingle) {
frame.origin.x +=200;
frame.origin.y +=60;
bigImage.alpha = 0.5;
} else {
frame.origin.x -=200;
frame.origin.y -=60;
bigImage.alpha = 1;
}
bigImage.frame = frame;
/**************************動畫屬性方式等配置******************************/
[UIView commitAnimations];//2.開始提交動畫 ????????(結束主要點)
2.Block塊使用方式
Block塊類方法介紹:
/**????????????????????????????????Block塊執(zhí)行動畫????????????????????????????**/
//動畫時間树肃,執(zhí)行動畫(block塊)
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations ; // delay = 0.0, options = 0, completion = NULL
//動畫時間笛谦,執(zhí)行動畫(block塊)嘉赎,完成后的操作(block塊)
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion ;
//動畫時間愕提,動畫延遲開始時間试伙,動畫行動方式劈狐,執(zhí)行動畫(block塊)胀葱,完成后的操作(block塊)
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion ;
//動畫時間,動畫延遲開始時間唇牧,動畫行動方式罕扎,執(zhí)行動畫(block塊)聚唐,完成后的操作(block塊)
/**特別介紹(??????)物理仿真效果(??????)
1.usingSpringWithDamping: 阻尼(彈簧動畫)相當于摩擦力的大小,范圍:[0.0 ~ 1.0]
說明:a.靠近 0腔召,阻尼小杆查,彈動幅度大 ; b.靠近 1,阻尼大臀蛛,彈動幅度小
2.initialSpringVelocity:彈簧動畫的速率
說明: a. initialSpringVelocity = 0亲桦,表示忽略改屬性,只計算阻尼+動畫效果
b. initialSpringVelocity > 0浊仆,表示 值越小客峭,彈簧拉伸幅度小抡柿;
值越大舔琅,彈動拉伸幅度越大;
*/
+ (void)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
usingSpringWithDamping:(CGFloat)dampingRatio
initialSpringVelocity:(CGFloat)velocity
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion ;
/**??????????????????????????????????????????????????????????????????????**/
Block使用方式:
[UIView animateWithDuration:1 //執(zhí)行時間
delay:0.0 //延遲執(zhí)行時間
options:UIViewAnimationOptionCurveEaseInOut//執(zhí)行方式
animations:^{ //開始操作
CGRect frame = bigImage.frame;
if (!isSingle) {
frame.origin.x +=200;
frame.origin.y +=60;
bigImage.alpha = 0.5;
} else {
frame.origin.x -=200;
frame.origin.y -=60;
bigImage.alpha = 1;
}
bigImage.frame = frame;
} completion:^(BOOL finished) { //操作結束
NSLog(@"動畫完成后,需要執(zhí)行的操作");
}];