Search code examples
iosxcodeswifttoday-extension

Today Extension view re-adjusts itself after view appears. iOS Swift


From the storyboard, I set constraints:

1) Leading space to: Superview = 0

2) Trailing space to: Superview = 0

When today extension loads, there is this little margin offset in the beginning, then disappears after done showing the view.

enter image description here

Then after view-did-appear:

enter image description here

I tried setting "Leading space to: Superview" and "Trailing space to: Superview" to -8, -16.0 etc. But nothing worked. The offset margin showing up in the beginning still shows up to a different value as I changed the constraint value.

How can I prevent this re-adjustment from happening?


Solution

  • If you don't already do so, try adjusting your views in viewWillAppear. This should make sure that once the elements become visible on screen, they are already laid out correctly. I had a similar issue and this fixed it for me.