iOS-动画效果(首尾式动画,代码快动画,核心动画,序列帧动画)

一.各个动画的优缺点

1.首尾动画:如果只是修改空间的属性,使用首尾动画比较方便,如果在动画结束后做后续处理,就不是那么方面了。

2.核心动画:有点在于对后续的处理方便。

3.块动画:

(1)在实际的开发中更常用的时block代码块来处理动画操作。

(2)块动画相对来说比较灵活,尤为重要的是能够将动画相关的代码编写在一起,便于代码的阅读和理解.

4.使用序列帧动画:对UIImageview和button按钮进行连线。

 #import "ViewController.h"

 @interface ViewController ()
{
UIView *_view;
UIImageView *_imageView;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; //用于block代码快动画,核心动画,UIView封装的首尾式动画
_view = [[UIView alloc] init];
_view.frame = CGRectMake(, , , );
_view.backgroundColor = [UIColor redColor];
[self.view addSubview:_view]; //用于序列帧动画
_imageView = [[UIImageView alloc] init];
_imageView.frame = CGRectMake(, , , );
_imageView.backgroundColor = [UIColor orangeColor];
[self.view addSubview:_imageView];
} #pragma mark 序列帧动画
//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
// NSMutableArray * arrayM = [NSMutableArray array];
//
//
// for (int i = 0; i < 4; i ++) {
// [arrayM addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",i]]];
// }
// //设置动画数组
// [_imageView setAnimationImages:arrayM];
//
// //设置动画播放次数 MAXFLOAT:无穷大数,表示一直循环下去
// [_imageView setAnimationRepeatCount:MAXFLOAT];
//
// //设置动画播放时间(图片个数 * 计划的每张照片动画时长)
// [_imageView setAnimationDuration:4 * 0.75];
//
// //开始动画
// [_imageView startAnimating];
//} #pragma mark block代码快动画
//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
//
// [UIView animateWithDuration:2.0 animations:^{
// NSLog(@"动画开始执行前的位置: %@",NSStringFromCGPoint(_view.center));
// _view.center = CGPointMake(self.view.bounds.size.width - 20, self.view.bounds.size.height - 20);
//
//
// } completion:^(BOOL finished) {
// NSLog(@"动画执行完毕后的位置: %@",NSStringFromCGPoint(_view.center));
// }];
//} #pragma mark 核心动画
//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
// //创建核心动画
// CABasicAnimation * animation = [CABasicAnimation animation];
//
// //平移
// animation.keyPath = @"position";
//
// //设置执行的动画
// animation.toValue = [NSValue valueWithCGPoint:CGPointMake(self.view.bounds.size.width - 20, self.view.bounds.size.height - 20)];
//
// //设置动画的时长
// animation.duration = 2.0f;
//
// //设置动画执行完毕之后不删除动画
// animation.removedOnCompletion = NO;
//
// //设置保存动画的最新状态
// animation.fillMode = kCAFillModeForwards;
//
// //设置动画的代理
// animation.delegate = self;
//
// //给控件添加核心动画
// [_view.layer addAnimation:animation forKey:nil];
//}
//#pragma mark 核心动画开始时调用的方法
//- (void)animationDidStart:(CAAnimation *)anim
//{
// NSLog(@"动画开始执行前的位置: %@",NSStringFromCGPoint(_view.center));
//}
//#pragma mark 核心动画结束时调用的方法
//- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
//{
// NSLog(@"动画执行完毕后的位置: %@",NSStringFromCGPoint(_view.center));
//} #pragma mark UIView封装的首尾式动画
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
NSLog(@"动画执行之前的位置: %@",NSStringFromCGPoint(_view.center)); //首尾式动画
//执行动画
[UIView beginAnimations:nil context:nil]; //动画时间
[UIView setAnimationDuration:2.0f]; //设置动画的代理
[UIView setAnimationDelegate:self]; //设置动画执行完毕调用的事件
[UIView setAnimationDidStopSelector:@selector(didStopAnimation)]; _view.center = CGPointMake(self.view.bounds.size.width - , self.view.bounds.size.height - ); //动画结束
[UIView commitAnimations];
} #pragma mark 动画执行完毕调用的方法
- (void)didStopAnimation
{
NSLog(@"动画执行完毕"); NSLog(@"动画执行之后的位置: %@",NSStringFromCGPoint(_view.center));
} @end
上一篇:jQuery EasyUI弹出确认对话框(确认操作中.....)


下一篇:Ubuntu 安装系统资源托盘监视应用