转换视图

时间:2015-04-20 05:35:19

标签: ios objective-c iphone

我希望沿Y轴变换视图。我的代码工作正常但是他们在一秒钟之后回到它的原始位置。我不需要这个。

CABasicAnimation* animation =[CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
animation.fromValue = @(0);
animation.toValue = @( M_PI/4);
animation.repeatCount = 0.0;
animation.duration = 5.0;

[self.view.layer addAnimation:animation forKey:@"rotation"];

CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0 / 500.0;
self.view.layer.transform = transform;

3 个答案:

答案 0 :(得分:1)

如果您希望视图停止在动画停止的位置,请尝试使用

animation.fillMode = kCAFillModeForwards;

答案 1 :(得分:0)

当您在使用其presentationLayer而不是modelLayer的图层上应用动画时,您会将图层快照回原始值,因为您仍然没有修改模型图层。登记/> 为了使事情有效,您还需要更新模型层,因为保持表示层具有值而模型具有其他值可能会导致进一步的问题。

CABasicAnimation* animation =[CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
animation.fromValue = @(0);
animation.toValue = @( M_PI/4);
animation.repeatCount = 0.0;
animation.duration = 5.0;

[self.view.layer addAnimation:animation forKey:@"rotation"];
self.view.layer.transform = //Apply the transformation


此外,在动画结束之前,再次应用一个转换,除了它的透视组件与原始图层相同 如果要在动画结束时执行此操作,则应设置CABasicAnimation的委托。
有关详情,请查看herehere

答案 2 :(得分:0)

让您查看已完成动画的最后状态。并且在完成时不会删除动画。

animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;

希望这能帮到你..