在仅限纵向应用程序中以横向模式添加子视图

时间:2013-03-19 13:00:52

标签: iphone ios6 orientation

我的应用是一款仅适用于肖像的应用。我需要在横向模式下添加子视图。对于要添加的新视图,我在iOS 6中设置了以下方向。

-(NSUInteger)supportedInterfaceOrientations
{
    NSUInteger options = UIInterfaceOrientationMaskAll;

    if (self.inAppBrowserOrientation)
     {
        if (self.inAppBrowserOrientation == UIInterfaceOrientationLandscapeLeft || self.inAppBrowserOrientation == UIInterfaceOrientationLandscapeRight)
        options = UIInterfaceOrientationMaskLandscape;
        return options;
    }
}

视图将以纵向模式添加。在方向上,此视图将仅在横向模式下旋转,这是预期的。

首次添加视图时,为什么它会以纵向模式添加?而self.inAppBrowserOrientationUIInterfaceOrientationLandscapeRight

2 个答案:

答案 0 :(得分:2)

尝试使用以下代码段

-(NSUInteger)supportedInterfaceOrientations
{
    NSUInteger options = UIInterfaceOrientationMaskAll;

    if (self.inAppBrowserOrientation)
     {
        if (self.inAppBrowserOrientation == UIInterfaceOrientationLandscapeLeft || self.inAppBrowserOrientation == UIInterfaceOrientationLandscapeRight)
        options = UIInterfaceOrientationMaskLandscape;
        return options;
    }
    else
    {
        return UIInterfaceOrientationMaskLandscape;
    }

}

我不确定,但是当您第一次加载aqpp时可能会出现问题

享受编程!!

答案 1 :(得分:2)

- (void)viewDidAppear:(BOOL)animated
{ 
    [super viewDidAppear:animated];

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(270));
    landscapeTransform = CGAffineTransformTranslate (landscapeTransform, 0.0, 0.0);
    [[self navigationController].view setTransform:landscapeTransform];
    self.navigationController.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
    self.navigationController.navigationBar.frame = CGRectMake(0.0, 20.0, 480, 44.0);


} 

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];   

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(0));
    landscapeTransform = CGAffineTransformTranslate (landscapeTransform, 0.0, 0.0);
    [[self navigationController].view setTransform:landscapeTransform];
    self.navigationController.view.bounds = CGRectMake(0.0, 0.0, 320, 480);
    self.navigationController.navigationBar.frame = CGRectMake(0.0, 20.0, 320.0, 44.0);

}

这里,Default Orientation是Portrait,但是当编译器转到viewDidAppear时,它将旋转270度,因此在横向模式下。 相应地调整框架尺寸......

祝你好运!!