When opening an iOSView, when does auto-layout actually set control sizes?

Hey everyone,

I’ve got a feeling that I’m missing something obvious here, so I’m hoping that someone can point out exactly what flavour of idiot I am :wink:

I have a canvas on an iOSView that uses auto-layout to set its height and width. When initialising the view, I want to do some stuff based on the height and width that the control will have once the auto-layout rules have been applied. However, in all of the obvious event handlers (iOSView.Open, iOSView.Activate, iOSView.Resized, iOSCanvas.Open) the control reports its height and width as being a default size. It’s only when iOSCanvas.Paint fires that the control has had its auto-layout rules applied.

In the case of an iOSCanvas control, using iOSCanvas.Paint to handle this particular case is going to be fine for me, but if this were a different type of control I wouldn’t have that option.

Can anyone suggest an event handler that’s part of the opening/activating process that will fire after auto-layout rules have been applied?

I’ve created a sample project that illustrates the problem. View2.HowBigAmI is called from each of those event handlers, and only reports the final size once we get to iOSCanvas.Paint:

Sample project

Why not use a tiny canvas Paint event just for that purpose ?

Thanks for the suggestion, Michel. Yes, that would work just fine as a workaround: it just doesn’t feel very elegant, does it? TBH, I’m surprised that when the iOSView.Resized event fire the auto-layout rules haven’t already been applied.

Sometimes pragmatism has to take precedence over elegance. Especially in such a spartan environment as Xojo iOS, one has to make due. You can file a feature request to get a “View.autolayoutComplete” event, though. One never knows. Miracles happen.

It does make sense that auto layout takes place AFTER Resized. if you think about it, auto layout needs to happen after the view has settled in its new size or orientation.

Um… I am assuming (probably correctly) that XOJO for iOS does not expose this basic event?

[quote]
Use “viewDidLayoutSubviews” for this. Apple’s documentation says, “Called to notify the view controller that its view has just laid out its subviews.”[/quote]

You can safely assume that not even the normal complement of events in Desktop has been exposed. Much less those specific to iOS. Think Crayola, not anything for adults.

but even then you only get the green and yellow crayon :slight_smile:

viewDidLayoutSubviews would be the wrong thing since that would not be be “this control just resized”

I quickly asked Joe about this and it does look like the resized event is being raised at the wrong point in time - hence what you’re seeing

Please file a bug report about this

Thanks, Norman: done. I did think it was a little odd, but I’m still learning the subtleties of the iOS framework so wasn’t sure if I hadn’t just missed something.

<https://xojo.com/issue/43548>