代码之家  ›  专栏  ›  技术社区  ›  progrmr

uiviewController加载旋转到横向,但仅支持纵向

  •  2
  • progrmr  · 技术社区  · 14 年前

    即使父视图控制器(和电话)是横向的,有没有办法在纵向加载仅纵向的视图控制器?

    这个特殊的uiviewController只适用于纵向模式(它是一个颜色选择器),因此shouldAutoToInterfaceOrientation中的代码:只对纵向方向返回yes。如果你在视图已经加载的情况下打开手机,它会保持纵向,但是当视图的笔尖加载时,如果手机已经处于横向,这就没有帮助了。

    加载ViewController时,当屏幕已经处于横向时,视图处于纵向布局,并且视图的下半部分被切断。我试图提出一个景观布局,但分割控制是一个问题。

    编辑 -我试过在视图中使用setstatusbarorientation,但它只会影响状态栏,导航栏和视图仍会旋转以实现横向效果。

    iPhone上的3.1.3和4.0会发生这种情况。

    4 回复  |  直到 12 年前
        1
  •  6
  •   Johan Kool    14 年前

    如果它适用于你的应用程序,你可以考虑使用模态视图控制器。IIRC提供了一个模态视图控制器,可以正确地处理旋转。

        2
  •  2
  •   cyborch    14 年前

    在这个例子中,我希望视图以横向模式开始,即使它是从纵向模式推出来的。

    
    @implementation MyView
    -(void)layoutSubviews {
        // Set subview frames here
        switch ([UIDevice currentDevice].orientation) {
            case UIDeviceOrientationUnknown:
            case UIDeviceOrientationPortrait:
            case UIDeviceOrientationPortraitUpsideDown:
            case UIDeviceOrientationFaceUp:
            case UIDeviceOrientationFaceDown:
                self.transform = CGAffineTransformMakeRotation(M_PI/2.0);
                self.transform = CGAffineTransformTranslate(self.transform, -80.0f, 80.0f);
                break;
            case UIDeviceOrientationLandscapeLeft:
            case UIDeviceOrientationLandscapeRight:
                self.transform = CGAffineTransformIdentity;
                break;
        }
    }
    @end
    
    

    @implementation MyController -(void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration { [self.view setNeedsLayout]; } @end

        3
  •  1
  •   Ed Marty    14 年前

    在正常情况下,当显示新的 UIViewController 如果它只支持纵向,并且应用程序当前处于横向,那么它应该自动旋转到纵向。这只适用于较新版本的操作系统(但我假设您可能在3.1.3上运行?).

    在任何情况下,要强制应用程序进入纵向:

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
    
        4
  •  0
  •   Michael Kessler    14 年前

    我认为不可能将纵向视图控制器推到已经处于横向模式的导航控制器上。
    尝试想象它的动画(导航栏)。

    我建议您为颜色选择器添加一个横向模式。

    另一种解决方案可能是在以横向模式进入颜色选择器时旋转整个视图。
    您可以通过 [[UIDevice currentDevice] orientation] .