您的位置:首页 > 其它

核心动画

2016-03-06 13:22 405 查看
1. 无缝动画

- (void)awakeFromNib {

iphone每秒刷新60次, 屏幕刷新的时候就会触发

CADisplayLink *link = [CADisplayLink displayLinkWithTarget:selfselector:@selector(setNeedsDisplay)];

[link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];

}

- (void)drawRect:(CGRect)rect {

self.snowY += 1;

UIImage *image = [UIImage imageNamed:@"雪花"];

将image 放在 view上的某一点上

[image drawAtPoint:CGPointMake(0, self.snowY)];

if (self.snowY > self.frame.size.height) {

self.snowY = 0;

}

}

2. CATransition

CATransition *animation = [CATransition animation];

动画种类

animation.type = @"pageCurl";

//typedef enum : NSUInteger {

// fade = 1, //淡入淡出

// push, //推挤

// reveal, //揭开

// moveIn, //覆盖

// cube, //立方体

// suckEffect, //吮吸

// oglFlip, //翻转

// rippleEffect, //波纹

// pageCurl, //翻页

// pageUnCurl, //反翻页

// cameraIrisHollowOpen, //开镜头

// cameraIrisHollowClose, //关镜头

// curlDown, //下翻页

// curlUp, //上翻页

// flipFromLeft, //左翻转

// flipFromRight, //右翻转

//

//} AnimationType;

动画种类的模式

animation.subtype = subtype;

// CA_EXTERN NSString * const kCATransitionFromRight

// CA_EXTERN NSString * const kCATransitionFromLeft

// CA_EXTERN NSString * const kCATransitionFromTop

// CA_EXTERN NSString * const kCATransitionFromBottom

animation.duration = 0.5;

[self.imageView.layer addAnimation:animation forKey:nil];

移除self.imageView.layer上的
所有动画

[self.imageView.layer removeAllAnimations];

3. CABasicAnimation

CABasicAnimation *animation1 = [CABasicAnimation animation];

animation1.keyPath = @"transform.rotation";

animation1.toValue = @M_PI_2;

CABasicAnimation *animation2 = [CABasicAnimation animation];

animation2.keyPath = @"transform.scale";

animation2.toValue = @0.5;

CABasicAnimation *animation3 = [CABasicAnimation animation];

animation3.keyPath = @"position";

animation3.toValue = [NSValue valueWithCGPoint:CGPointMake(100, 250)];

//
创建动画组

CAAnimationGroup *group = [CAAnimationGroup animation];

//
动画数组

group.animations = @[animation1, animation2, animation3];

group.duration = 2;

// 保持动画结束效果

group.removedOnCompletion = NO;

group.fillMode = kCAFillModeForwards;

[self.redView.layer addAnimation:group forKey:nil];

// self.view
执行 UIViewAnimationOptionTransitionCurlUp
动画

[UIView transitionWithView:self.view duration:0.5 options:UIViewAnimationOptionTransitionCurlUp animations:nil completion:nil];

4. CAKeyframeAnimation

CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];

// 动画要修改的属性
的 key

animation.keyPath = @"transform.rotation";

// 动画要修改的属性
的 values

animation.values = @[@(angleWithRotation(-5)), @(angleWithRotation(5)), @(angleWithRotation(-5))];

animation.duration = 0.5;

animation.repeatCount = MAXFLOAT;

// 动画结束后不移除动画效果

animation.removedOnCompletion = NO;

// 向图层添加
动画

[self.imageView.layer addAnimation:animation forKey:nil];

5. 图层动画

添加涂层

- (void)createLayer {

//
创建一个涂层

CALayer *layer = [CALayer layer];

//
设置尺寸(涂层的大小)

layer.bounds = CGRectMake(0, 0, 100, 100);

//
设置位置(锚点显示在position上)

layer.position = CGPointMake(100, 100);

//
设置颜色

layer.backgroundColor = [UIColor redColor].CGColor;

//
设置内容

layer.contents = (__bridge id _Nullable)[UIImage imageNamed:@"阿狸头像"].CGImage;

// anchorPoint:
绕锚点旋转

layer.anchorPoint = CGPointMake(0.5, 1);

[self.mainView.layer addSublayer:layer];

}

[UIView animateWithDuration:0.5 animations:^{

//
缩放

self.mainView.layer.transform = CATransform3DMakeScale(0.5, 0.5, 1);

//
平移

self.mainView.layer.transform = CATransform3DMakeTranslation(100, 100, 100);

//
旋转

self.mainView.layer.transform = CATransform3DMakeRotation(M_PI, 0, 1, 0);

}];

6.CABasicAnimation

CABasicAnimation *animation = [CABasicAnimation animation];

// 动画修改的属性
的 key

animation.keyPath = @"transform.scale";

// 动画修改的属性
的 value

animation.toValue = @0.5;

// 动画时长

animation.duration = 0.5;

// 动画重复次数

animation.repeatCount = MAXFLOAT;

// 动画结束后不移除动画效果

animation.removedOnCompletion = NO;

// 保持最新的位置

animation.fillMode = kCAFillModeForwards;

// 给图层添加动画

[self.layer addAnimation:animation forKey:nil];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: