提出的UIViewController拒绝旋转

时间:2013-09-12 17:09:14

标签: iphone ios uiviewcontroller rotation

我在我的应用程序中使用DDMenuController来获取像facebook app这样的抽屉。

当导航一切都很完美时,使用推送方法,视图旋转完美,无需做​​任何事情; 但是当我使用[self present ...]或[self.navigationcontroller present ...]时,视图会注意到旋转,事件会更糟,控制器会收缩并改变位置。

如果按下相同的视图则旋转正常。 supportedInterfaceOrientation支持所有但是颠倒应该autorotate返回yes。

Iphone中的短信部分类似于我想要做的事情,在uibevigation栏顶部的uinavigation栏中有一个uitabbutton,它提供了一个带有uinavigation bar和uitextfield的新uiviewController。 uinavigation按钮有一个取消uitabbutton和一个save uitabbutton。

谢谢

1 个答案:

答案 0 :(得分:0)

我在我的一个项目中旋转视图控制器时遇到问题,最后我实现了这个解决方案,希望它能帮到你。

- (void)viewDidLoad
{
    [super viewDidLoad];
    isShowingLandscapeView = NO;
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(orientationChanged:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil];
    // Do any additional setup after loading the view.
}
-(BOOL) shouldAutorotate{
    return NO;
}

- (void)orientationChanged:(NSNotification *)notification
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    CGRect rect = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width);;


    switch (deviceOrientation) {
        case 1:
            [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.1];
            self.view.transform = CGAffineTransformMakeRotation(0);
            self.view.bounds = [[UIScreen mainScreen] bounds];
            [UIView commitAnimations];
            break;
        case 2:
            [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown animated:NO];
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.1];
            self.view.transform = CGAffineTransformMakeRotation(-M_PI);
            self.view.bounds = [[UIScreen mainScreen] bounds];
            [UIView commitAnimations];
            break;
        case 3:
            [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
            //rect = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width);
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.1];
            self.view.transform = CGAffineTransformMakeRotation(M_PI_2);
            self.view.bounds = rect;
            [UIView commitAnimations];
            break;
        case 4:
            [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.1];
            //rect = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width);
            self.view.transform = CGAffineTransformMakeRotation(-M_PI_2);
            self.view.bounds = rect;
            [UIView commitAnimations];
            break;

        default:
            break;
    }
}

更新:

-(NSUInteger) supportedInterfaceOrientations{
    return UIInterfaceOrientationPortrait;
}