我正在尝试使用SWRevealViewController
使我的应用程序在设备转向横向时自动显示侧面板,并且我可以在应用程序最初打开但不在此之后执行此操作。基本上我试图使它的行为有点像iPad上的Mail应用程序,除了你仍然可以在横向模式下手动关闭侧面板。我在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;
}
有人可以告诉我我应该做什么吗?
答案 0 :(得分:1)
我终于明白了。一种更简单的方法是简单地将以下代码添加到前视图控制器:
- (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旋转到横向模式时,侧面板会自动打开;当我将其旋转回纵向模式时,它会关闭侧面板。