iOS Objective-C基本核心动画,偏移,旋转,缩放,路径,抖动,组动画
来源:互联网 发布:minitab 两组数据分析 编辑:程序博客网 时间:2024/05/01 16:13
/*
主要思路就是创建CABasicAnimation、CAKeyframeAnimation、CAAnimationGroup对象,编写相应的动画效果后添加到view的layer里面。
*/
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) CALayer *redLayer;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.redLayer = [CALayer layer];
self.redLayer.bounds = CGRectMake(0, 0, 100, 100);
self.redLayer.position = CGPointMake(100, 100);
self.redLayer.backgroundColor = [UIColor redColor].CGColor;
[self.view.layer addSublayer:self.redLayer];
// [self test01];
// [self test02];
// [self test03];
// [self test04];
// [self test05];
[self test06];
}
//组动画:多个动画同时进行
- (void) test06{
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
//1.路径
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(100, 100, 200, 100)].CGPath;
//2.旋转
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotationAnimation.byValue = @(M_PI * 2);
//3.缩放
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transfrom.scale"];
scaleAnimation.toValue = @(0.5);
animationGroup.animations = @[pathAnimation, rotationAnimation, scaleAnimation];
animationGroup.duration = 3;
animationGroup.repeatCount = CGFLOAT_MAX;
[self.redLayer addAnimation:animationGroup forKey:nil];
}
//抖动
- (void) test05{
CAKeyframeAnimation *keyAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
keyAnimation.values = @[@(-M_PI_4/4), @(M_PI_4/4), @(-M_PI_4/4)];
keyAnimation.repeatCount = CGFLOAT_MAX;
// keyAnimation.duration = 0.25; //all animation's duration is 0.25
[self.redLayer addAnimation:keyAnimation forKey:nil];
}
//按指定路径走的动画
- (void) test04{
CAKeyframeAnimation *keyAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
keyAnimation.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(100, 100, 200, 100)].CGPath;
keyAnimation.duration = 3;
[self.redLayer addAnimation:keyAnimation forKey:nil];
}
//基本动画,旋转
- (void) test03 {
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
basicAnimation.toValue = @(M_PI * 2);
basicAnimation.repeatCount = 10;
basicAnimation.removedOnCompletion = NO;
basicAnimation.fillMode = kCAFillModeForwards;
[self.redLayer addAnimation:basicAnimation forKey:nil];
}
//基本动画,缩放
- (void) test02 {
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
//缩小小于1, 放大大于1
basicAnimation.toValue = @0.5;
basicAnimation.duration = 3;
basicAnimation.removedOnCompletion = NO;
basicAnimation.fillMode = kCAFillModeForwards;
[self.redLayer addAnimation:basicAnimation forKey:nil];
}
//基本动画,移动
- (void) test01{
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
basicAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(300, 300)];
basicAnimation.duration = 3;
basicAnimation.removedOnCompletion = NO;
basicAnimation.fillMode = kCAFillModeForwards;
[self.redLayer addAnimation:basicAnimation forKey:nil];
}
@end
- iOS Objective-C基本核心动画,偏移,旋转,缩放,路径,抖动,组动画
- ios 动画(抖动,入场动画,组动画)
- ios 旋转缩放等动画
- IOS 基本动画(旋转、移动、闪烁、缩放等)
- iOS - iOS平移旋转动画 通过核心动画实现(动画组)
- 自定义动画--角度抖动、路径旋转、左右晃动
- iOS:核心动画之基本动画CABasicAnimation
- iOS动画 基本动画操作和长按控件抖动
- iOS核心动画基本要点
- ios 抖动动画效果
- ios抖动动画效果
- ios抖动动画效果
- iOS 抖动动画
- iOS 视图抖动动画
- iOS左右抖动动画
- [CAAnimation核心动画练习一]普通的平移,旋转,缩放
- iOS动画 核心动画
- Android 同时播放缩放动画和位移动画 时, 位移的路径会发生偏移.
- [sh2log]Linux键盘记录 keylogger notes
- Python面向对象编程(二)
- 利用nandsim挂载ubi文件系统
- LeetCode 266. Palindrome Permutation(对称排列)
- Android Studio中快速提取方法
- iOS Objective-C基本核心动画,偏移,旋转,缩放,路径,抖动,组动画
- 下载好自动安装
- js之JavaScript 面向对象介绍 ----谷营中西软件科技园
- iOS 引导图的聚光灯效果代码实现
- 码农必须知道的几个名词(持续更新...)
- ViewPager+Fragment组成滑动且带有光标
- Git的下载安装与使用
- 第70课:SparkSQL内置函数解密与实战学习笔记
- div中position的相对绝对路径的详解