0

I'm trying to make my app using SWRevealViewController show the side panel automatically when the device is turned to landscape orientation, and I can make it do so when the app initially opens but not after that. Basically I'm trying to make it behave somewhat like the Mail app on the iPad except that you can still manually close the side panel on landscape mode. I tried this in the AppDelegate without success:

#import "AppDelegate.h"
#import "SWRevealViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    SWRevealViewController *revealViewController = (SWRevealViewController *)self.window.rootViewController;

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if (orientation == UIInterfaceOrientationPortrait) {

    }   
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {

        if (revealViewController.frontViewPosition == FrontViewPositionLeft) {
            [revealViewController revealToggleAnimated:YES];           
        }
    }
    return YES;
}

Can anyone please tell me what I should be doing instead?

GenieWanted
  • 4,473
  • 4
  • 24
  • 35
user2330922
  • 141
  • 1
  • 6

1 Answers1

1

I finally figured it out. A much simpler approach is to simply add the following code to the front view controller:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    [self openSidePanel:interfaceOrientation];
}

- (void)openSidePanel:(UIInterfaceOrientation)orientation
{
    if (UIInterfaceOrientationIsLandscape(orientation)) {
        [self.revealViewController setFrontViewPosition:FrontViewPositionRight animated:YES];
    }
    else {
        [self.revealViewController setFrontViewPosition:FrontViewPositionLeft animated:YES];
    }

}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [self openSidePanel:toInterfaceOrientation];
}

Now, when I rotate my iPad to landscape mode, the side panel automatically opens; and when I rotate it back to portrait mode, it closes the side panel.

user2330922
  • 141
  • 1
  • 6
  • Im having an issue where when the iphone is in portrait mode, the swrevealcontroller works find and allows the user to scroll when the menu is opened. When it goes into landscape mode the menu slides opened as expected but i cant scroll to all the options in the menu!? Have you encountered this issue? – Famic Tech Feb 28 '17 at 00:38