Orientation Portrait and PortraitUpSideDown Only For One Window

偶尔善良 提交于 2019-12-25 08:31:51

问题


I have 10 windows.

The initial window is loginWindow i want to set orientation for Portrait and PortraitUpSideDown. For remaining windows will have landscape and portrait orientation.

in Tiapp.xml

        <key>UISupportedInterfaceOrientations~iphone</key>
        <array>
            <string>UIInterfaceOrientationPortrait</string>
            <string>UIInterfaceOrientationPortraitUpsideDown</string>
            <string>UIInterfaceOrientationLandscapeLeft</string>
            <string>UIInterfaceOrientationLandscapeRight</string>
        </array>

Which set all orientation for my application which enables portrait,portraitupsidedown,landscapeLeft and landscapeRight.

I need those only portrait and portraitUpSideDown for LoginWindow.
Rest of window do have all the orientation which is portrait,portraitupsidedown,landscapeLeft and landscapeRight.

Can any one suggest me how can i able to get this behaviours for my application.


回答1:


You need to use different windows and define for each window which orientation you want to allow.

I mean, you have to create loginWindow like this:

var loginWindow = Ti.UI.createWindow({
    orientationModes : [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT],
    fullscreen : false,
    navBarHidden : true

});
winPortrait.orientationModes = [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT];

Windows where you want to allow all orientations, have to been created like this:

var appWindow = Titanium.UI.createWindow({

    width : Ti.UI.FILL,
    height : Ti.UI.FILL,
    fullscreen : false,
    navBarHidden : true,
    orientationModes : [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]
});
appWindow.orientationModes = [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT];

Hope it helps




回答2:


Present your loginWindow as a modal view and after that set this methods for desired orientations.

- (BOOL) shouldAutorotate
{            
    return NO;
}

 - (NSUInteger) supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}



回答3:


Using different orientation modes for a single app in iOS is not recommended. Please read Orientation design principles

Apple's Developer documentation says: "People expect to use your app in different orientations, and it’s best when you can fulfill that expectation." In other words, don't look at handling orientation as a bother but an opportunity.

Apple further recommends that when choosing to lock or support orientation, you should consider following these principles:

On iPhone/iPod Touch – Don't mix orientation of windows within a single app; so, either lock orientation for the whole app, or react to orientation changes.

On iPhone – don't support the portrait-upside-down orientation because that could leave the user with their phone upside-down when receiving a phone call.

However you can achieve orientation for particualr window using the orientationMode property of window



来源:https://stackoverflow.com/questions/21873547/orientation-portrait-and-portraitupsidedown-only-for-one-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!