0

我在我的应用程序中使用 DDMenuController 来拥有像 facebook 应用程序这样的抽屉。

当导航一切都完美时,使用 push 方法,视图完美旋转而不做任何事情;但是当我使用 [self present...] 或 [self.navigationcontroller present...] 时,视图确实会旋转,更糟糕的是控制器会缩小并改变位置。

如果它被推动,相同的视图可以很好地旋转。如果 autorotate 返回 yes,supportedInterfaceOrientation 可以支持除了颠倒之外的所有内容。

Iphone 中的 sms 部分类似于我想要做的,在 uitable 顶部的 uinavigation 栏,在 uinavigation 栏中有一个 uitabbutton,它呈现一个带有 uinavigation 栏和 uitextfield 的新 uiviewController。uinavigation 按钮有一个取消 uitab 按钮和一个保存 uitab 按钮。

谢谢

4

1 回答 1

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;
}
于 2013-09-12T17:53:15.280 回答