iOS layer 动画
x軸縮放:
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.scale.x"];
theAnimation.duration=8;
theAnimation.removedOnCompletion = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:1];
theAnimation.toValue = [NSNumber numberWithFloat:0.5];
?[yourView.layer addAnimation:theAnimation forKey:@"animateTransform"];
y軸縮放:
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
theAnimation.duration=8;
theAnimation.removedOnCompletion = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:1];
theAnimation.toValue = [NSNumber numberWithFloat:0.5];
?[yourView.layer addAnimation:theAnimation forKey:@"animateTransform"];
x軸,y軸同時按比例縮放:
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
theAnimation.duration=8;
theAnimation.removedOnCompletion = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:1];
theAnimation.toValue = [NSNumber numberWithFloat:0.5];
?[yourView.layer addAnimation:theAnimation forKey:@"animateTransform"];
以上縮放是以view的中心點為中心縮放的,如果需要自定義縮放點,可以設置卯點:
//中心點
[yourView.layer setAnchorPoint:CGPointMake(0.5, 0.5)];
//左上角
[yourView.layer setAnchorPoint:CGPointMake(0, 0)];
//右下角
[yourView.layer setAnchorPoint:CGPointMake(1, 1)];
轉載于:https://www.cnblogs.com/XXxiaotaiyang/p/5043327.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的iOS layer 动画的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用FiddlerCore来测试WebA
- 下一篇: NASA称巨型小行星正靠近地球:时速超8