iOS视图弹跳动画
//动画弹跳效果关键代码
弹跳多次可自行多嵌套几次 调用此方法 只需传入弹跳对象
- (void)animationShootOut:(UIView *)animationView{
CGRect frame = animationView.frame;
[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseIn animations:^(void){
} completion:^(BOOL finished){
[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void){
//弹起
animationView.frame = CGRectMake(frame.origin.x, frame.origin.y-20, frame.size.width, frame.size.height);
} completion:^(BOOL finished){
[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseIn animations:^(void){
//下降
animationView.frame = frame;
} completion:^(BOOL finished){
[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void){
//弹起
animationView.frame = CGRectMake(frame.origin.x, frame.origin.y-10, frame.size.width, frame.size.height);
} completion:^(BOOL finished){
//下降
[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void){
animationView.frame = frame;
} completion:^(BOOL finished){
}];
}];
}];
}];
}];
}
突然发现这样太麻烦 要是想多跳几次就要写很多了,所以刚刚又封装了一下 就是感觉跳动不流畅 太生硬 暂时没什么思路解决
封装的就是用一个C 函数递归调用 感觉还行
//弹射动画函数
void shootOutAnimation(UIView *view ,int n,float height,CGRect frame,int num) {
//n 为弹跳的次数 如果传入的是一个基数 那么就会自动默认加一为偶数
//height 为第一次弹跳的最高高度 20
//view 为传入的视图
//frame 为传入视图的坐标
//num 必须和传入的弹跳次数一致
if (n<0) {
return;
}
n = n-1;
[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseIn animations:^(void){
view.frame = CGRectMake(frame.origin.x, frame.origin.y-((n%2)?0:(n+2)*(height/num)), frame.size.width, frame.size.height);
} completion:^(BOOL finished){
shootOutAnimation(view, n, height, frame,num);
}];
}