3

I am looking to update a UIView thats in a storyboard (and instantiated from the storyboard) when it loads in the app.

I need to position a few icons in a dynamic way (that the interface builder doesn't let me do quite yet). However, if I put my code in viewDidAppear or viewDidLoad, it seems to be getting called too late.

Here is what happens the first few second or two when the view loads:

initial load

And then a bit later it goes to the right position (as the code was called).

Fixed position a second later

My question is where do I need to initialize the positions of these objects so they dont snap over a second later. viewDidLoad and viewDidAppear are too late? Why!? :)

override func viewDidAppear(animated: Bool)
{
    initView()
    _gridLines = false

}

func initView()
{
    _cameraFeed.initAfterLoad()
    //center the buttons on half distance between middle button and screen edge
    var middleDistance:CGFloat = _swapButton.frame.origin.x + _swapButton.frame.width/2
    _linesButton.frame.origin.x = middleDistance/2 - _linesButton.frame.width/2
    _flashButton.frame.origin.x = middleDistance + middleDistance/2 - _flashButton.frame.width/2
    _selectPhotos.frame.origin.x = middleDistance/2 - _selectPhotos.frame.width/2
}

Swift and objc answers welcome!

pkamb
  • 33,281
  • 23
  • 160
  • 191
Aggressor
  • 13,323
  • 24
  • 103
  • 182

1 Answers1

4

Try putting the code setting the frame in viewWillAppear instead of viewDidAppear.

Also, you should call the super.

override func viewWillAppear(animated: Bool) {
    initView()
    _gridLines = false

    super.viewWillAppear(animated)
}
SefTarbell
  • 342
  • 2
  • 12
  • Sadly this did not work :(. In fact it didn't even move the icons over this time, they just froze on the right side – Aggressor Oct 24 '14 at 19:20