简体   繁体   English

纵向和横向iPad的差异UI

[英]Difference UI for portrait and landscape ipad

I would like to create an application like this: 我想创建一个这样的应用程序: 在此处输入图片说明

On iphone (both portrait and landscape) and ipad portrait, I have a table view screen, tap on item row will navigate to another detail screen look like other basic application. 在iPhone(纵向和横向)和iPad纵向上,我都有一个表格视图屏幕,点击项目行将导航到另一个详细信息屏幕,就像其他基本应用程序一样。
But when I rotate screen to go to landscape on ipad, the screen now has two section views 但是,当我旋转屏幕以在ipad上横向移动时,屏幕现在具有两个剖面图
Here is what I did: 这是我所做的:

  • Write a method isInLandscapeTablet to detect ipad landscape 编写isInLandscapeTablet方法来检测iPad横向
  • Use UINavigationController as a root controller to control all other views 使用UINavigationController作为根控制器来控制所有其他视图
  • In portrait screen, push a viewcontroller contains tableview to root controller 在纵向屏幕中,将包含tableview的viewcontroller推送到根控制器
  • In landscape tablet screen, attach tableview controller and detail controller to UISplitViewController , then push it into root controller 在横向平板电脑屏幕中,将tableview控制器和detail控制器附加到UISplitViewController ,然后将其推入根控制器

But the problem is I can't push UISplitViewController to root controller, as it requires to be a root controller. 但是问题是我不能将UISplitViewController推送到根控制器,因为它需要成为根控制器。
I wonder how I can handle this problem 我不知道如何解决这个问题
And is my approach correct? 我的方法正确吗? Is there any other way? 还有其他办法吗?

Update : I change the root view controller like this 更新 :我这样更改根视图控制器

  // this snippet is in UINavigationController (I use as root viewcontroller) 
        if([self isInTabletLandscape]){
             self.splitViewController.viewControllers = [NSArray arrayWithObjects:[[CategoryViewController alloc] initWithNibName:@"CategoryViewController" bundle:nil], self.propertyLandViewController, nil];
            [[UIApplication sharedApplication].keyWindow setRootViewController:self.splitViewController];
        }else{
 // it doesn't work
            [[UIApplication sharedApplication].keyWindow setRootViewController:self];
            }
        }

After knowing the device whether it is iPad or iPhone. 知道设备是iPad还是iPhone后。 You Can try to remove the RootViewController. 您可以尝试删除RootViewController。

       appDelegate.window.rootViewController = nil;

Then you set the root view controller with a new SplitViewContloller 然后使用新的SplitViewContloller设置根视图控制器

        id objClass =[[SplitViewController alloc]initWithNibName:@"SplitViewController" bundle:nil];
        masterVC.delegate = detailVC;
        detailVC.delegate = objClass;
        [objClass setViewControllers:@[masterNavigate,detailNavigate]];

        [appDelegate.window setRootViewController:objClass];

If you are developing on iOS 8 you should use Size Classes , so you can totally change the layout depending on iPhone/iPad portrait and iPad Landscape. 如果您是在iOS 8上进行开发,则应使用Size Classes ,以便可以完全根据iPhone / iPad portrait和iPad Landscape更改布局。 Unfortunately on iOS 7, size classes only differentiate iPhone and iPad. 不幸的是,在iOS 7上,尺寸类别只能区分iPhone和iPad。

In both case the right part (2), can be easily handle with a containerView. 在这两种情况下,正确的部分(2)都可以使用containerView轻松处理。

My suggestion is not to use Split View Controller at all. 我的建议是根本不要使用Split View Controller。 Create a custom View Controller, which will embed your table view controller and the 2nd controller. 创建一个自定义视图控制器,它将嵌入您的表视图控制器和第二个控制器。 Also, you can implement the interface-rotation logic in the custom controller you create. 另外,您可以在创建的自定义控制器中实现接口旋转逻辑。

https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/SplitViewControllers.html https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/SplitViewControllers.html

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   MyFirstViewController* firstVC = [[MyFirstViewController alloc] init];
   MySecondViewController* secondVC = [[MySecondViewController alloc] init];

if ( ([[UIDevice currentDevice] orientation] ==  UIDeviceOrientationPortrait)  ){

   UISplitViewController* splitVC = [[UISplitViewController alloc] init];
   splitVC.viewControllers = [NSArray arrayWithObjects:firstVC, secondVC, nil];

    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    window.rootViewController = splitVC;
   [window makeKeyAndVisible];
 }
    else
{
// Display tableview

}
 return YES;
 }


I assume this may help you.. 我认为这可能对您有帮助。

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

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