Portrait / Landscape

How do you handle moving from Portrait to Landscape. I would like to reposition some items is it possible and how do you detect which mode your in?

Thanks

[quote=200182:@Richard Albrecht]How do you handle moving from Portrait to Landscape. I would like to reposition some items is it possible and how do you detect which mode your in?

Thanks[/quote]

You get a Resized event when the user rotates, and then you check View.ContentSize to see if width < height or not. That is where to reposition elements of pushto different views (one for Landscape, one for Portrait).

See this project I made during Beta: Buddha.zip

So it looks like you have a completely different View, one for Landscape and one for Portrait, correct?

So changing constraints on the fly to fix the layout isn’t recommended.

Then it would be a good idea to have all methods in a module.

Not sure the purpose of the timer?

Since you did this back in the beta is this still how you would do it?

I just read in the Docs:

So it must be possible to have one layout that adjusts itself. I would assume by changing auto layout values in code, though maybe you don’t have to do it in code you just need to set priorities correctly?

Going to do some more studying.

[quote=200373:@Richard Albrecht]I just read in the Docs:
So it must be possible to have one layout that adjusts itself. I would assume by changing auto layout values in code, though maybe you don’t have to do it in code you just need to set priorities correctly?

Going to do some more studying.[/quote]

Of course you can use Auto Layout to change things. I use the very same example for RubberViewsWE at http://rubberviews.com/rubberviewswe.html where instead of having two views (Webpages, but the concept is the same), I modify constraints to show different layouts.

[quote=200353:@Richard Albrecht]Not sure the purpose of the timer?
Since you did this back in the beta is this still how you would do it?[/quote]

The PushTimer and CloseView timers are probably there to prevent issues pushing or closing views in one view’s event. I forgot, but they are surely there to prevent some errors.

As you say it has been a while. At the time it was not possible to modify the constraints on the fly, so I had no choice other than switching views. Today I could use the same principle as what I do in Xojo Web with RubberViewsWE.

There is no absolute, here. For relatively simple layout modifications, I would think modifying constraints is the way to go. For more elaborate UI, I am inclined to believe using two views is far easier, since you can tune the appearances of views much easier visually, than having to set every single control constraint (which in iOS you got to name first).

In the app I have in the App Store, I have used yet a third approach.

In portrait as above, fonts are on top of each other. When rotated, auto layout creates very shallow and very wide canvases on top of each other where the characters are much too small. So instead, I want to show them side by side. At the time, I could not modify the constraints (same problem as in Buddha), so I managed that by placing the canvases where they pertain, but I set their visibility in Resize.

As you see, you can play on many things to modify layout upon rotation.

Thank you for the detailed post.

Have you found away to determine if it’s running on an iPad or iPhone?

[quote=200383:@Richard Albrecht]
Have you found away to determine if it’s running on an iPad or iPhone?[/quote]

There was a thread about that here https://forum.xojo.com/18242-what-device-am-i/0

There was never a definite way to get the kind of the device, though.

For the time being, I would check the screen size of 1024 x 768. It is the same for all iPads, including Mini.

http://ios-resolution.com/

[quote=200388:@Michel Bujardet]There was a thread about that here https://forum.xojo.com/18242-what-device-am-i/0

There was never a definite way to get the kind of the device, though.

For the time being, I would check the screen size of 1024 x 768. It is the same for all iPads, including Mini.

http://ios-resolution.com/[/quote]

and don’t get confused between POINTS and PIXELS… as Michel said all (current) iPads are 1024x768 (POINTS) where the Retina one is 2048x1536 PIXELS (ie 4 pixels=1 point [@2x]), on the iPad2 (non-Retina) 1 point=1 pixel [@1x]

Then of course you get into non-iPad where the iPhone6+ is 414x736 POINTS and 1242x2208 PIXELS [@3x]

[quote=200403:@Dave S]and don’t get confused between POINTS and PIXELS… as Michel said all (current) iPads are 1024x768 (POINTS) where the Retina one is 2048x1536 PIXELS (ie 4 pixels=1 point [@2x]), on the iPad2 (non-Retina) 1 point=1 pixel [@1x]

Then of course you get into non-iPad where the iPhone6+ is 414x736 POINTS and 1242x2208 PIXELS [@3x][/quote]

Indeed what is important here is the size property of the view. Anyway, Xojo iOS does not have a method to return the screen points.

The tricky part is that depending on orientation, Self.Size.Width is 1024 or 768, same thing for Height.

Untested, but according to SO this should work:

const FoundationLib = "Foundation.framework" const UIKitLib = "UIKit.framework" declare function NSClassFromString lib FoundationLib (clsName as CFStringRef) as ptr declare function currentDevice_ lib UIKitLib selector "currentDevice" (clsRef as ptr) as ptr declare function model_ lib UIKitLib selector "model" (obj_id as ptr) as CFStringRef dim model as Text = model_(currentDevice_(NSClassFromString("UIDevice"))) dim isIPad as boolean = model.BeginsWith("iPad")

An easier way to do this is for the defaultScreens (iPhone and iPad) to refer to a different view(eg vPad, vPhone) whose open event sets app.is_iPad as boolean.