【问题标题】:After iPad is unplugged from Mac the animation called in viewDidAppear doesn't happen从 Mac 上拔下 iPad 后,viewDidAppear 中调用的动画不会发生
【发布时间】:2013-12-05 04:46:33
【问题描述】:

我的应用的代码工作流程如下:viewDidLoad->viewDidAppear->create subview->animate subview

动画使子视图从一个非常小的转换到它应该的大小,给它一个类似于 UIAlert 显示的效果。当我从我的 Mac 运行应用程序时,我拥有的代码可以完美运行,但在我拔下 iPad 并自行运行后,不知何故不想这样做。我尝试退出该应用程序并再次尝试,甚至竭尽全力重新启动 iPad 以使其正常工作,但无济于事。

这是我的代码:

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self setUpScreen];
}

还有 setUpScreen 方法...

// Populates the setUpView with various other items (unimportant for the issue in question)
setUpView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[self.view addSubview:setUpView];
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut
                 animations:^{
                     setUpView.transform = CGAffineTransformIdentity;
                 }
                 completion:^(BOOL finished){
                 }];

再次重申我的问题,当应用程序直接从 Xcode 运行时,“放大”动画效果很好,但当应用程序在没有 Xcode 帮助的情况下运行时,则无法这样做(视图只是出现在那里)。

我尝试在 animatewithDuration: 方法中添加延迟,并且我还尝试在调用 setUpView 方法之前添加睡眠。我愿意尝试任何事情。

此外,当按下按钮时,子视图会随着动画消失,并且无论我如何运行应用程序,该动画都可以正常工作,我唯一的问题是在启动时。

【问题讨论】:

    标签: animation uiview viewdidappear


    【解决方案1】:

    我发现 [super viewDidAppear:animated] 和 [self setUpScreen] 之间的 [NSThread sleepForTimeInterval:0.1] 不够长(我在发布问题之前尝试过的解决方案之一)。似乎将时间间隔设为 0.5 可以解决我的问题。但是,如果有更好的解决方案,请分享。

    【讨论】:

      猜你喜欢
      • 2015-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-29
      • 1970-01-01
      相关资源
      最近更新 更多