iphone/ipad orientation handling

后端 未结 6 962
盖世英雄少女心
盖世英雄少女心 2020-11-30 21:52

This is more of a general question for people to provide me guidance on, basically Im learning iPad/iPhone development and have finally come across the multi-orientation sup

6条回答
  •  抹茶落季
    2020-11-30 22:18

    In your question, you wrote:

    I can just imagine so many issues with spaghetti code/thousands of "if" checks all over the place, that it would drive me nuts to make one small change to the UI arrangement.

    One way to dodge this is to make a view hierarchy that splits the handling of iPhone/iPad specific changes from the very beginning. You'd only have to set which view is initially loaded for each device. Then you create a viewcontroller like you normally do, but you also subclass the viewcontroller you've created. One subclass for each device. That's where you can put the device specific code, like orientation handling. Like this:

    MyViewController.h            // Code that is used on both devices
        MyViewController_iPhone.h // iPhone specific code, like orientation handling
        MyViewController_iPad.h   // iPad specific code, like orientation handling
    

    If you are interested in this approach, I'd suggest that you read this article. It explains it in a very nice way.

    One of the things the article mentions, is this:

    --start of quote--

    The beauty of this pattern is we don’t have to litter our code with crap that looks like this:

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        // The device is an iPad running iPhone 3.2 or later.
        // set up the iPad-specific view
    } else {
        // The device is an iPhone or iPod touch.
        // set up the iPhone/iPod Touch view
    }
    

    ---end of quote--

    I hope that helps. Good luck!

提交回复
热议问题