Positioning objects while reorienting to iPad

iPad Gurus: Apple wants us to support all orientations. I believe this means that a particular layout should either rotate so that all objects are positioned relative to the same OR, if that doesn't look good, then they should be moved, or two views should be designed and built.

If I rely on the built-in rotation mechanism, objects either change, or cross the edge of the page in the same orientation, or disappear altogether from view. It seems I can’t find the correct settings so that the objects are aligned exactly so that they appear in every orientation.

Moving results in many if statements in the view controller. Therefore, I do not think that Apple had this in mind.

I tried to replace the views and even view the controllers in the "willRotateToInterfaceOrientation" method, but this either crashes or the book views suddenly appear and vv. Moreover, two view controllers mean double coding for the same view.

There should be a proper way to handle orientation changes, but I searched the internet, documentation, and sample code in vain for something that works. How is this done correctly?

Thanks!

+4
source share
4 answers

Spend some time in the Builder interface to understand what “automation” and “size and position” do (size inspector). They can be configured separately for each UILabel, Button, Bar, Image, etc.

In addition, scaling for filling, aspect, filling aspect, etc., is also useful for understanding (inspector attribute).

Remember to override shouldAutorotateToInterfaceOrientation to return YES, and then everything should work using the same UIViewController and UIView.

0
source

Recommended and direct way to do this:

  • Add all of your routines to the main view in the nib file or in the viewDidLoad controller viewDidLoad .
  • Override the view of the view manager of the layoutSubviews . In this method, check whether the orientation of the view is portrait or landscape, and set the frame property for each subview according to your desired size and position for that orientation.
  • Calling the [self layoutSubviews] method in the controller method -willRotateToInterfaceOrientation:duration: Note - layoutSubviews can be called automatically when the view rotates, I don’t remember. If not, call it yourself.
0
source

Head off to GitHub and see the NextMunich NMM class (and NMViewController too). Very very powerful and quite easy to implement. Basically, it was created for people who need a more complex hierarchy of views, but don’t want to write a lot of additional code to handle orientation. He does it for you as soon as you post it.

Exemption. I stole some of my ideas on viewing animations when I picked up their brains a bit. They are super friendly people.

0
source

Thanks to an excellent entry at OranLooney.com I managed to get the java / icefaces web application to resize nicely on the ipad.

donnothing (); in window.orientchangechange there is, as it seems, sometimes without it, resizing (sometimes) does not work, in your case, although I assume that this is exactly where you want to put the code to start a new view.

 // a function to parse the user agent string; useful for // detecting lots of browsers, not just the iPad. function checkUserAgent(vs) { var pattern = new RegExp(vs, 'i'); return !!pattern.test(navigator.userAgent); } if ( checkUserAgent('iPad') ) { // iPad specific stuff here window.onorientationchange = function() { donnothing(); }; } 

also, if you figure out how to enable double-click, let us know!

-1
source

Source: https://habr.com/ru/post/1309153/


All Articles