Skip to content

filipe-nunes/Cordova-Orientation-Lock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;

About

Cordova Plugin to Toggle Orientation Lock

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 47.4%
  • Java 30.0%
  • JavaScript 22.6%