【问题标题】:Orientation Methods not responding when one view controller view is added as sub view将一个视图控制器视图添加为子视图时,方向方法没有响应
【发布时间】:2011-10-07 14:44:52
【问题描述】:

我正在开发一个应用程序,在该应用程序中单击按钮时,我必须将一个类控制器视图显示为子视图。 我已将视图控制器添加为子视图,它工作正常。

TempViewControlleriPad *tempScreen=[[TempViewControlleriPad alloc]initWithNibName:@"TempViewControlleriPad" bundle:nil];
[self.view addSubview:tempScreen.view];
[tempScreen viewWillAppear:NO];

现在,当我旋转我的设备方向时,我的子视图没有响应该方向意味着我的子视图没有旋转。

TempViewControlleriPad orientation method:-


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
             [[NSBundle mainBundle] loadNibNamed:@"TempViewControlleriPad" owner:self options:nil];
    }
    else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
         [[NSBundle mainBundle] loadNibNamed:@"TempViewControlleriPadLandscape" owner:self options:nil];
    }

    return YES;

}

请建议我应该怎么做才能解决这个方向问题。

提前致谢。

【问题讨论】:

    标签: iphone objective-c addsubview orientation-changes


    【解决方案1】:

    子视图的控制器是UIViewController吗? 您不应该在另一个中嵌入视图控制器。来自 Apple 文档:

    您不应该使用多个自定义视图控制器来管理 同一视图层次结构的不同部分。同样,您应该 不要使用单个自定义视图控制器对象来管理多个 屏幕价值的内容。 http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/AboutViewControllers/AboutViewControllers.html#//apple_ref/doc/uid/TP40007457-CH112-SW12

    您可以在子视图上设置自动调整大小的掩码。

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多