【发布时间】:2014-08-08 06:34:17
【问题描述】:
我有一些核心动画代码可以在根视图控制器 (VC1) 上完美运行,但是当我将根更改为与 VC1 连接的另一个视图控制器 (VC2) 时,VC1 上的动画永远不会运行,即使它的动画方法被调用。有趣的是,如果我在 segue 上关闭动画,VC1 上的核心动画就会起作用。
这是我对 VC1 的实现:
CAShapeLayer* circleLayer;
- (void)setupCircle
{
CGPathRef circlePath = CGPathCreateWithEllipseInRect(CGRectMake(10, 40, 100, 100), nil);
circleLayer = [CAShapeLayer layer];
circleLayer.path = circlePath;
circleLayer.fillColor = [UIColor orangeColor].CGColor;
circleLayer.strokeColor = [UIColor blueColor].CGColor;
circleLayer.lineWidth = 10;
[self.view.layer addSublayer:circleLayer];
}
- (void)animateCircle
{
CABasicAnimation* circleAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
circleAnimation.duration = 4;
circleAnimation.fromValue = @0;
circleAnimation.toValue = @1;
[circleLayer addAnimation:circleAnimation forKey:@"circleAnimation"];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupCircle];
[self animateCircle];
}
有什么问题?谢谢。
【问题讨论】:
-
加我到 amir.ios。我想看实际代码
-
尝试在 ViewDidAppear 中调用 [self setupCircle] 和 [self animateCircle] 而不是 ViewDidLoad
标签: ios objective-c uiviewcontroller core-animation