【问题标题】:Core Animation not working when not root View Controller不是根视图控制器时核心动画不起作用
【发布时间】: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


【解决方案1】:

但是当我将根更改为另一个视图控制器 (VC2) 时 继续 VC1

您的循环中的问题是 viewDidLoad,如果您从子 VC 回来,它不会被调用。

把东西放在viewWillAppearviewDidAppear

【讨论】:

    【解决方案2】:

    你可以试试这段代码;

    [self performSelector:@"setupCircle" withObject:nil afterDelay:0.1];
    [self performSelector:@"animateCircle" withObject:nil afterDelay:0.1];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多