I am searching for a alternative for viewDidLayoutSubviews
that is only called once.
I use this code to move the login out of the view:
override func viewDidLayoutSubviews() {
username_input.center.x -= view.bounds.width
password_input.center.x -= view.bounds.width
login_button.center.x -= view.bounds.width
}
I need to do this once, so that I can then move it in with a animation when viewDidAppear
. This all worked great till I split my View into different subviews and now the function is called multiple times. I could't find any equivalent functions to this that is only called once.
Define a boolean that turns to false
the first time viewDidLayoutSubviews
executes. I did this many times and it works just fine.
fileprivate var firstLayoutSubviewsTime = true
override func viewDidLayoutSubviews() {
if firstLayoutSubviewsTime {
firstLayoutSubviewsTime = false
[...]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With