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;
雪花"];
将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 {
淡入淡出
推挤
揭开
覆盖
立方体
吮吸
翻转
波纹
翻页
反翻页
开镜头
关镜头
下翻页
上翻页
左翻转
右翻转
//
//} 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];
// 动画要修改的属性 的
animation.keyPath = @"transform.rotation";
// 动画要修改的属性 的
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;
设置内容
阿狸头像"].CGImage;
绕锚点旋转
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];
// 动画修改的属性 的
animation.keyPath = @"transform.scale";
// 动画修改的属性 的
animation.toValue = @0.5;
// 动画时长
animation.duration = 0.5;
// 动画重复次数
animation.repeatCount = MAXFLOAT;
// 动画结束后不移除动画效果
animation.removedOnCompletion = NO;
// 保持最新的位置
animation.fillMode = kCAFillModeForwards;
// 给图层添加动画
[self.layer addAnimation:animation forKey:nil];