您的位置:首页 > 移动开发 > IOS开发

ios layer 动画-(transform.scale篇)

2013-11-07 17:16 253 查看
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)];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: