Ios 如何使用滑动菜单为单个视图设置横向方向?

Ios 如何使用滑动菜单为单个视图设置横向方向?,ios,iphone,objective-c,Ios,Iphone,Objective C,我正在使用SWRevealViewController实现滑动菜单。我的应用程序正在portait模式下运行。但我想在横向模式下打开视图控制器。 此视图控制器在单击滑动菜单的一个视图时打开。 我已经搜索了Stackoverflow,但所有需要的UINavigationcontroller都要设置为AppDelegate中的rootViewController。 但是在我的例子中,SWrevealViewController被设置为窗口的rootviewController。 请帮我提供一些线索。

我正在使用
SWRevealViewController
实现滑动菜单。我的应用程序正在portait模式下运行。但我想在横向模式下打开视图控制器。 此视图控制器在单击滑动菜单的一个视图时打开。 我已经搜索了Stackoverflow,但所有需要的
UINavigation
controller都要设置为AppDelegate中的rootViewController。 但是在我的例子中,
SWrevealViewController
被设置为窗口的
rootviewController
。 请帮我提供一些线索。

试试这个:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}


我已经通过在视图中使用下面的代码解决了我的问题,该视图将显示为横向模式

- (NSUInteger)supportedInterfaceOrientations
{

    return UIInterfaceOrientationMaskLandscapeLeft;
}


-(void)viewDidAppear:(BOOL)animated
{
    if(UIDeviceOrientationIsPortrait(self.interfaceOrientation)){
        if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
        {
            objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft );
        }
    }
}


-(void)viewDidDisappear:(BOOL)animated{

    if(UIDeviceOrientationIsLandscape(self.interfaceOrientation)){
        if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
        {
            objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationPortrait );
        }
    }
}

谢谢,但我已经在Project Explorer>常规设置中设置了portait模式。此处需要进行任何更改。是的,如果您希望横向定向OK,则需要将其设置为两者。但是写了上面的方法之后,,在Project explorer设置中设置横向模式后,它给出了错误复制方法。所有视图都将在lanscape或portait模式下开始旋转。但我不想旋转任何其他视图,因为@SamkitJain建议您必须在常规设置中设置方向,并在创建时覆盖所有页面的上述给定方法必修的。对于两个方向,使用两个,否则只返回Potrait。如果我在“常规设置”中设置了两个方向,并根据需要覆盖所有页面的上述给定方法。对于两个方向,使用两个,否则仅返回Potrait。然后所有的视图都有旋转功能。我已经试过了,正如你所说。看起来你在调用一个私有API,不是吗?不,我是SWRevealViewController库,用于创建类似滑动菜单的滑动facebook,这是一个开放的市场source@MarcMosby如果我做错了,请告诉我。我说的是
objc_msgSen
部分。你能解释一下objc_msgSec吗,因为我不知道,我只是用了它,它工作正常,苹果对它们的使用有任何限制,请指导我。谢谢你的回复
- (NSUInteger)supportedInterfaceOrientations
{

    return UIInterfaceOrientationMaskLandscapeLeft;
}


-(void)viewDidAppear:(BOOL)animated
{
    if(UIDeviceOrientationIsPortrait(self.interfaceOrientation)){
        if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
        {
            objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft );
        }
    }
}


-(void)viewDidDisappear:(BOOL)animated{

    if(UIDeviceOrientationIsLandscape(self.interfaceOrientation)){
        if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
        {
            objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationPortrait );
        }
    }
}