Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIView.animateWithDuration应用程序启动后立即显示_Ios_Swift_Animation_Uiview_Uiviewanimation - Fatal编程技术网

Ios UIView.animateWithDuration应用程序启动后立即显示

Ios UIView.animateWithDuration应用程序启动后立即显示,ios,swift,animation,uiview,uiviewanimation,Ios,Swift,Animation,Uiview,Uiviewanimation,我有一个奇怪的问题,我叫UIView.animateWithDuration in viewDid出现在我的应用程序的初始视图控制器上,但动画似乎会跳转,它会在中途某个地方可见。我找到的唯一解决方法是在开始动画之前添加延迟。我很想了解为什么会发生这种情况,以及是否有比延迟更好的解决方案 若要自己尝试,请创建一个单一视图应用程序,然后在ViewController中添加以下方法。swift Xcode debugger会稍微减慢应用程序的速度,若要模拟真实情况,请停止并从设备或模拟器启动应用程序:

我有一个奇怪的问题,我叫UIView.animateWithDuration in viewDid出现在我的应用程序的初始视图控制器上,但动画似乎会跳转,它会在中途某个地方可见。我找到的唯一解决方法是在开始动画之前添加延迟。我很想了解为什么会发生这种情况,以及是否有比延迟更好的解决方案

若要自己尝试,请创建一个单一视图应用程序,然后在ViewController中添加以下方法。swift Xcode debugger会稍微减慢应用程序的速度,若要模拟真实情况,请停止并从设备或模拟器启动应用程序:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    let redSquare = UIView(frame: CGRectMake(0, 0, 50, 50))
    redSquare.backgroundColor = UIColor.redColor()
    redSquare.center = view.center

    view.addSubview(redSquare)

    UIView.animateWithDuration(0.5) { () -> Void in
        var newFrame = redSquare.frame
        newFrame.origin.y -= 200
        redSquare.frame = newFrame
    }
}
红方块应该从屏幕的中心开始平移到顶部的某个位置,但这就好像动画开始了,但应用程序还没有准备好显示它,所以你可以看到红方块从中心上方开始平移


编辑:在示例中添加对viewDidAppear的调用并不能解决问题。

不确定问题是否出在这里,但您是否尝试过在制作动画之前调用super.viewDidAppear?实际上我已经这样做了,我只是在示例中忘记了它。我复制并粘贴了您的代码到一个空项目中。它按照您的要求对我非常有效。