Core Animationコアアニメーション使用
1744 ワード
@interface ViewController ()
@property (nonatomic, weak) CALayer *layer;
//位置を変更するためのボタン
@property (nonatomic, weak) UIButton *button; (void)viewDidLoad { [super viewDidLoad]; [self setupLayer];
}
pragma mark-コアアニメーション直接修正layer-(void)setupLayer{
}
//方法-(void)demoLayer 1{
} -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self demoLayer3]; }
pragma mark-回転-(void)demoLayer 3{ CABasicAnimation*animation=[CABasicAnimation animation animation WithKeyPath:@"transform.rotation.z";anim.duration=2; 属性anim.toValue=@(M_PI*2*5); [self.layer addAnimation:animforKey:nil]; を追加
}
-(void)demoLayer2 {コアアニメーションCABasicAnimation*animation=[CABasicAnimation animation animation WithKeyPath:@"bounds.size"; アニメーション属性anim.toValue=[NSValue valueWithCGSize:CGSizeMake(500,500)];//anim.duration=0.5;anim.repeatCount=CGFLOAT_MAX; layerに追加[self.layer addAnimation:animforKey:nil]; }
@property (nonatomic, weak) CALayer *layer;
//位置を変更するためのボタン
@property (nonatomic, weak) UIButton *button;
}
pragma mark-コアアニメーション直接修正layer-(void)setupLayer{
// MARK: - 1. layer
// 1.
CALayer *layer = [CALayer layer];
// 2. ,
layer.backgroundColor = [UIColor yellowColor].CGColor;
// bounds frame
layer.bounds = CGRectMake(0, 0, 150, 150);
layer.position = CGPointMake(200, 300);
// 3.
[self.view.layer addSublayer:layer];
// 4.
_layer = layer;
}
//方法-(void)demoLayer 1{
// MARK: - 1.
// 1.
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position.y"];
// 0.25″,
anim.duration = 3;
// 2.
anim.toValue = @200;
anim.byValue = @300;
// 2.2
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeForwards;
// 3. layer
[self.layer addAnimation:anim forKey:nil];
} -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self demoLayer3]; }
pragma mark-回転-(void)demoLayer 3{
}
-(void)demoLayer2 {