0

我有一个 parentViewController,它使用 Delegate UITableViewController 调用模态 ViewController。问题是我没有导航堆栈来从父级的 shouldAUtoRotate 中获取值。

由于 shouldAutorotate 从未触发,因此它从返回 NO 且无法更改的主控制器获取它。有没有办法操纵模态控制器以将正确的 shouldAutorotate 设置为 YES?

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.pv dismiss:YES];
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
            //[self fullScreenAction:nil];
        } else {
//            [self exitFullScreenAction:nil];
        }
    }
}
-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        return UIInterfaceOrientationMaskAll;
    } else {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
}

//ios >=6
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

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

1 回答 1

0

I managed to solve my problem although is not the best solution, maybe for some will be useful.

So i create a new Category Controller in order to use it to set manually the Rotation calls.

.m

#import "UINavigationController+AutoRotate.h"

@implementation UINavigationController (AutoRotate)

- (BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationMaskAll;
}
@end

and .h

#import <UIKit/UIKit.h>

@interface UINavigationController (AutoRotate)

- (BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;

@end

And then the Modal was working as it should without a navigation controller.

于 2015-05-27T19:25:58.287 回答