初始化一个imageView,给定一个位置
self.shouImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 46)];
self.shouImageView.image = [UIImage imageNamed:@"new_shareHand11"];
self.shouImageView.center = CGPointMake(25, 23);
[self.shareBtn addSubview:self.shouImageView];
制定一个位移位置,开始动画
//位移动画
-(void)positionAnimation:(NSInteger)type{
NSLog(@"动画执行之前的位置:%@",NSStringFromCGPoint(self.shouImageView.center));
//首尾式动画
[UIView beginAnimations:nil context:nil];
//执行动画
//设置动画执行时间
[UIView setAnimationDuration:0.5];
//设置动画速度类别
//UIViewAnimationCurveEaseInOut, // 慢出慢入
//UIViewAnimationCurveEaseIn, // 慢出快入
//UIViewAnimationCurveEaseOut, // 快出慢入
//UIViewAnimationCurveLinear, // 匀速
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//设置代理
[UIView setAnimationDelegate:self];
if (type == 0) {
//设置动画执行完毕调用的事件
self.shouImageView.center = CGPointMake(35, 33);
[UIView setAnimationDidStopSelector:@selector(didStopAnimation)];
}else{
self.shouImageView.center = CGPointMake(25, 23);
}
[UIView commitAnimations];
//打印动画块的位置
NSLog(@"动画执行之后的位置:%@",NSStringFromCGPoint(self.shouImageView.center));
}
一次动画结束后,开始回到原始位置。
- (void)didStopAnimation{
[self positionAnimation:1];
}
至此一组位移动画已经结束啦。