Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在横向方向上自动打开SWRevealViewController侧面板_Ios_Objective C_Swrevealviewcontroller - Fatal编程技术网

Ios 如何在横向方向上自动打开SWRevealViewController侧面板

Ios 如何在横向方向上自动打开SWRevealViewController侧面板,ios,objective-c,swrevealviewcontroller,Ios,Objective C,Swrevealviewcontroller,我正在尝试使用SWRevealViewController使我的应用程序在设备转向横向时自动显示侧面板,并且我可以在应用程序最初打开时显示侧面板,但不能在打开后显示。基本上,我试图让它的行为有点像iPad上的邮件应用程序,只是你仍然可以在横向模式下手动关闭侧面板。我在AppDelegate中尝试了这一点,但没有成功: #import "AppDelegate.h" #import "SWRevealViewController.h" @implementation AppDelegate -

我正在尝试使用
SWRevealViewController
使我的应用程序在设备转向横向时自动显示侧面板,并且我可以在应用程序最初打开时显示侧面板,但不能在打开后显示。基本上,我试图让它的行为有点像iPad上的邮件应用程序,只是你仍然可以在横向模式下手动关闭侧面板。我在AppDelegate中尝试了这一点,但没有成功:

#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;
}

谁能告诉我应该做什么吗?

我终于明白了。更简单的方法是将以下代码简单地添加到前视图控制器:

- (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];
}

现在,当我将iPad旋转到横向模式时,侧面板会自动打开;当我将其旋转回纵向模式时,它会关闭侧面板。

我遇到了一个问题,当iphone处于纵向模式时,swrevealcontroller工作查找,并允许用户在打开菜单时滚动。当进入横向模式时,菜单按预期打开,但我无法滚动到菜单中的所有选项!?你遇到过这个问题吗?