简体   繁体   English

UITableViewController subView旋转

[英]UITableViewController subView rotation

I'm new to stackoverflow and to objective-C programming. 我是Stackoverflow和Objective-C编程的新手。 I have searched for the issue described below, but I'm not able to find a working solution. 我已经搜索了下面描述的问题,但是找不到有效的解决方案。

My application is a simple offline browsing app, with navigation structure. 我的应用程序是一个简单的脱机浏览应用程序,具有导航结构。 In the appDelegate I load the RootViewController (UITableViewController) in one of the following ways: 在appDelegate中,我通过以下方式之一加载RootViewController(UITableViewController):

Solution A 解决方案A

   [window addSubview:navigationController.view];
   [window makeKeyAndVisible];
   return YES;

Solution B 解决方案B

   RootViewController* rootviewcontroller = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];    
   navigationController = [[UINavigationController alloc] initWithRootViewController:rootviewcontroller];

The rootViewController simply push some views, ie rootViewController只是推送一些视图,即

 TipAndTrickViewController *mTipAndTrick = [[TipAndTrickViewController alloc]initWithNibName:@"TipAndTrickViewController" bundle:nil]; 
 [self.navigationController pushViewController:mTipAndTrick animated:YES];

In the deeper view I present a detail modalView (UIViewController). 在更深的视图中,我呈现了一个详细的modalView(UIViewController)。 What I want is to enable autorotate only in this last view. 我想要的是仅在最后一个视图中启用自动旋转。 The portait orientation is the desired for all the previoues wiews. 对于所有先前的想法,肖像取向是期望的。 The last view implements in the right way: 最后一个视图以正确的方式实现:

shouldAutorotateToInterfaceOrientation:interfaceOrientation 应该AutorotateToInterfaceOrientation:interfaceOrientation

shouldAutorotate 应该自动旋转

willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration willRotateToInterfaceOrientation:toInterfaceOrientation持续时间:持续时间

willAnimateRotationToInterfaceOrientation:interfaceOrientation duration:duration willAnimateRotationToInterfaceOrientation:interfaceOrientation持续时间:持续时间

Overriding 覆写

shouldAutorotate 应该自动旋转

shouldAutorotateToInterfaceOrientation:interfaceOrientation 应该AutorotateToInterfaceOrientation:interfaceOrientation

making them returning NO/YES in the rootViewController and setting the allowed orientation in the desired way, using 使他们在rootViewController中返回NO / YES,并使用所需的方式设置允许的方向,使用

supportedInterfaceOrientations 支持的接口方向

(both in rootViewCOntroller and in the last view), I get those results: (在rootViewCOntroller和最后一个视图中),我得到的结果是:

  • if I use Solution A all the views don't rotate. 如果我使用解决方案A,则所有视图都不会旋转。
  • if I use Solution B all the views always rotate. 如果我使用解决方案B,则所有视图都会旋转。

What I'm doing in the wrong way? 我做错了什么? Thank you in advance for your help 预先感谢您的帮助

Add these to your viewController and let me know if it works or not . 将它们添加到您的viewController中,让我知道它是否有效。

// iOS5 Rotation // iOS5旋转

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

// iOS6 Rotation // iOS6旋转

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (BOOL)shouldAutorotate
{
    return YES;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM