Skip to content

Latest commit

 

History

History
54 lines (40 loc) · 1.32 KB

README.md

File metadata and controls

54 lines (40 loc) · 1.32 KB

cordova-orientation-lock

A cordova plugin to lock and unlock the orientation of the UI programmatically.

Currently supports iOS and Android.

##Usage

 window.plugins.orientationLock.lock(function(){},function(){});
 window.plugins.orientationLock.unlock(function(){},function(){});

###Important Note for usage on iOS

In your XCode Project, set the preferences for all the orientations you want to have access to. if you want the app to lock in portrait, call lock() upon initialization of your webapp.

Add this to your MainViewController.m

- (NSUInteger)supportedInterfaceOrientations
{
    return self.canRotate ? UIInterfaceOrientationMaskAllButUpsideDown : UIInterfaceOrientationMaskPortrait;
}
// LEGACY iOS < 6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if(self.canRotate){
        return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    }
    else{
        if(interfaceOrientation == UIInterfaceOrientationMaskPortrait){
            return YES;
        }
        return NO;
    }
}

-(void)setRotationAllowed:(BOOL)value {
    _canRotate = value;
}

and this to your MainViewController.h

@property BOOL canRotate;
- (void)setRotationAllowed:(BOOL) value;