Animating view on viewDidAppear not working correctly - Swift
<p>I am trying to get a <code>view</code> to animate from the centre of the screen, to leave the screen after 1 second when the view loads. </p>

<p>The problem I am having is that after a millisecond of the <code>view</code> being in the original (correct) position upon loading, it then snaps to the new position and animates back to the original position. </p>

<p>I have the following code in <code>viewDidLoad</code></p>

<pre><code>override func viewDidAppear(animated: Bool) {

    UIView.animateWithDuration(0.7, delay: 1, options: .CurveEaseOut, animations: {
        var loadingViewFrame = self.loadingView.frame
        loadingViewFrame.origin.y += 600

        self.loadingView.frame = loadingViewFrame
        }, completion: { finished in
            print("moved")
    })


}
</code></pre>

<p>I have tried putting this code in a <code>button</code> action and it works fine, so is there some other method I should be using when animating on <code>viewWillAppear</code> or is there something else I have missed?</p>

<p>I have removed all autolayout constraints because I read that they may cause some problems.</p>

<p>I also have other code in <code>viewDidAppear</code> as well as <code>viewWillAppear</code> and <code>viewDidLoad</code> which I could show here if you think it is useful, but I have commented out all of this code to leave with only the basic code and the same error is still occurring.</p>

<p>Thanks a lot for your help.</p>

<hr>

<p>Edit 1</p>

<p>I have moved the code to <code>viewDidLayoutSubviews</code> and have used <code>dispatch_once</code> to ensure it is only done once. The image still animates from the new position to the original position, but now the image is not located in the original position for a millisecond upon loading.</p>

<p>This is the code I have added</p>

<pre><code>    var token: dispatch_once_t = 0

override func viewDidLayoutSubviews() {
    dispatch_once(&amp;token) {

        UIView.animateWithDuration(0.7, delay: 1, options: .CurveEaseOut, animations: {
            var loadingViewFrame = self.loadingView.frame
            loadingViewFrame.origin.x += 600

            self.loadingView.frame = loadingViewFrame
            }, completion: { finished in
                print("moved")
        })
    }
}
</code></pre>