UISplitviewcontroller 不作为 rootview 控制器

发布于 2024-09-27 04:14:46 字数 733 浏览 1 评论 0原文

我正在构建我的第一个 iPad 应用程序。我的要求之一是处理 UISplitviewcontroller 和 UINavigationController。
我们建议的视图层次结构是

(L​​oginView) ->UINavigationView(LandingView + CollectionView)->UISplitViewcontroller(DetailsView)。

我们的应用程序仅支持横向模式
我指的是这个SO问题(以及GILT应用程序),作为一个新手,它根据该描述,我很难完成它。

所以我的问题是
1)如果有人可以提供小代码片段或教程参考,我怎样才能实现同样的目标
2)根据苹果的HIG,UISplitviewcontroller应该是rootviewcontroller,如果不是怎么办。苹果会拒绝我的应用程序吗?(显然GILT组已经批准了)
3)我发现 MGSplitViewController ,我可以不以 root 身份使用它吗?
任何帮助将不胜感激。作为一个新手,我希望我的问题是真实的

I am building my first iPad application. And one of my requirements is to deal with UISplitviewcontroller and UINavigationController.
our proposed view hierarchy is

(LoginView) ->UINavigationView(LandingView + CollectionView)->UISplitViewcontroller( DetailsView).

Our app supports only landscape mode
I am referring this SO Question( and GILT app as well), as a newbi its hard for me to get it done based on that description.

So my questions are
1) How can I achieve same thing,if somebody can give small code snippets or reference to tutorial
2) As per Apples HIG, UISplitviewcontroller should be rootviewcontroller,what if it not. Will apple reject my app.(apparently GILT group has been approved)
3) I found MGSplitViewController , can I use that one not as root?
Any help would be appreciated. As a newbi i hope my question is genuine

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

最后的乘客 2024-10-04 04:14:46

如果您想使用开箱即用的 splitView,它必须是root;这里的任何欺骗行为要么会违反苹果的指导方针,要么会表现出非常奇怪的行为。

MGSplitViewController 是 SplitViewController 的完全自定义实现。如果您需要这类东西,那么它非常好,但是某些功能是基于我们的应用程序将定向的事实。

或者你也可以自己制作。我已经这样做过不止一次了,而且比听起来更容易。

(登录视图)
->UINavigationView(LandingView + CollectionView)->UISplitViewcontroller(
详情查看)。

基于开箱即用的 UISplitView,我建议:

  • 将 splitView 设为根视图。

  • 应用程序启动后立即弹出(非动画)全屏模态框并允许
    用户导航登录视图,
    LandingView和collectView在这;我还建议在此处使用 navController。

  • 一旦用户准备好继续
    splitView,填充
    splitView 的 rootView 控制器和
    DetailViewController 与任何
    然后,将模态动画显示出来。

戴夫确实有一点,但我会从这样的角度来看它:你正在消除用户的方向选择;因为设计者假设某些配置更有效而删除标准选择(例如支持的方向)只会惹恼某些用户。

If you want to use the out-of the box splitView it must be root; any hokeary-pokery here will either break apples guidelines or manifest very odd behaviour.

The MGSplitViewController is completely custom implementation of a SplitViewController. Its very good if you need that sort of thing, but some of the features are based round the fact that our app will be orientating.

Alternatively you could make your own. I have done this more than once and is easier than it sounds.

(LoginView)
->UINavigationView(LandingView + CollectionView)->UISplitViewcontroller(
DetailsView).

Based on an out-of-the-box UISplitView, I would suggest:

  • Make the splitView the root View.

  • Pop (not animated) a full screen Modal as soon as the app starts and allow the
    user to navigate the loginView,
    LandingView and collectView in this; i also recommend using a navController here.

  • Once the user is ready to proceed to
    the splitView, populate the
    splitView's rootView Controller and
    DetailViewController with whatever
    you want then ,animate the Modal out.

Dave does have a point, but i would look at it from the point of view that you are removing the choice of orientation from the user; removing standard choices (like supported orientations) because the designer assumes some configuration is more efficient will only annoy some users.

花开半夏魅人心 2024-10-04 04:14:46

我通过在我的 detailViewController 中创建一个方法来做到这一点:

-(void)popHomeScreen:(BOOL)animated//OPENS THE HOMESCREEN IN A MODAL DISPLAY
{

  firstRun=NO;
    //myViewControllerForPopOver init here

    myViewControllerForPopOver.modalPresentationStyle = UIModalPresentationFullScreen;  


        myViewControllerForPopOver.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;//simple anime

    if (animated) [self presentModalViewController:myViewControllerForPopOver animated:YES];
        else [self presentModalViewController:myViewControllerForPopOver animated:NO];  
    }

然后在 detailViewControllers 中调用它 ViewDidAppear 方法:

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
if(firstRun)[self popHomeScreen:NO];
}

//YOU WILL ALSO NEED TO MAKE 'firstRun=YES' in viewDidLoad
//firstRun is a BOOL

至于根消失(留下一个大的黑色空间)..这是一个已知的错误。虽然我想了一段时间,这是由于在动画要绘制自己之前/之前订购动画引起的。

另外,我发现,如果我在 splitView 上弹出一个全屏模式,然后在全屏模式无法正确绘制后很快弹出另一个基于表单的模式(例如)。

SplitViews 就像你的婆婆,你并不真正喜欢它们,当你必须使用它们时,你必须小心翼翼地避开地雷。

I did it by making a method in my detailViewController:

-(void)popHomeScreen:(BOOL)animated//OPENS THE HOMESCREEN IN A MODAL DISPLAY
{

  firstRun=NO;
    //myViewControllerForPopOver init here

    myViewControllerForPopOver.modalPresentationStyle = UIModalPresentationFullScreen;  


        myViewControllerForPopOver.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;//simple anime

    if (animated) [self presentModalViewController:myViewControllerForPopOver animated:YES];
        else [self presentModalViewController:myViewControllerForPopOver animated:NO];  
    }

Then Call it in the detailViewControllers ViewDidAppear method:

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
if(firstRun)[self popHomeScreen:NO];
}

//YOU WILL ALSO NEED TO MAKE 'firstRun=YES' in viewDidLoad
//firstRun is a BOOL

As for the root disappearing (leaving a big black space)..thats a known bug. though i thought for a while that it was caused by ordering an animation while/just before it was going to draw itself.

Also, i found that if i popped a full screen modal over the splitView then popped another form based modal (for example) quickly after it the full screen modal didn't draw properly.

SplitViews are like your mother-in-law, you don't really like them and when you have to use them you have to tip-toe round the landmines.

久光 2024-10-04 04:14:46

试试这个,它对我有用

1)在应用程序委托的didFinishLaunchingWithOptions中使您的登录视图也成为根视图

self.window.rootViewController = self.loginViewController;  

,像模板一样初始化分割视图(但不添加到self.window)

MasterViewController *masterViewController = [[[MasterViewController alloc] initWithNibName:@"MasterViewController_iPad" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];

    DetailViewController *detailViewController = [[[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:nil] autorelease];
    UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];

    self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
    self.splitViewController.delegate = detailViewController;
    self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController ,detailNavigationController, nil];

2)在应用程序的委托中添加一个交换视图控制器,它将根视图交换为分割视图控制器。

-(void)swapToViewControllers:(RootViewControllerType)viewType  
        self.window.rootViewController = self.splitViewController; 

3) 在登录视图中调用 swapToViewControllers。

Try this, it works for me

1) in app delegate's didFinishLaunchingWithOptions make your login view to root view

self.window.rootViewController = self.loginViewController;  

also, init the split view as the template do ( but not add to self.window)

MasterViewController *masterViewController = [[[MasterViewController alloc] initWithNibName:@"MasterViewController_iPad" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];

    DetailViewController *detailViewController = [[[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:nil] autorelease];
    UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];

    self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
    self.splitViewController.delegate = detailViewController;
    self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController ,detailNavigationController, nil];

2) add a swap view controller in app's delegate, which swap the root view to split viewcontroller.

-(void)swapToViewControllers:(RootViewControllerType)viewType  
        self.window.rootViewController = self.splitViewController; 

3) invoke the swapToViewControllers in your login view.

流殇 2024-10-04 04:14:46

请记住,HIG 强烈鼓励您支持所有方向。除非你有非常非常充分的理由只支持景观,否则你可能会被拒绝。

请参阅 HIG 第 19 页:http://developer。 apple.com/library/ios/documentation/General/Conceptual/iPadHIG/iPadHIG.pdf

Keep in mind that the HIG strongly encourages you to support all orientations. Unless you have a very, very good reason to support landscape only, you'll probably be rejected.

See page 19 of the HIG: http://developer.apple.com/library/ios/documentation/General/Conceptual/iPadHIG/iPadHIG.pdf

死开点丶别碍眼 2024-10-04 04:14:46

用故事板修改了 Ryan CY 的版本。

将此代码放入登录控制器。
1.设置UISplitViewController的storyboard id为SplitViewController;
2.设置UISplitViewController委托并保存实例

UISplitViewController* splitController = [self.storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"];
UINavigationController* navigationController = [splitController.viewControllers lastObject];
splitController.delegate = (id)navigationController.topViewController;

3. Change rootViewController after login

self.view.window.rootViewController = splitController;

Modified Ryan CY's version with storyboard.

Put this code to login controller.
1. Set storyboard id of UISplitViewController to SplitViewController;
2. Set UISplitViewController delegate and save instance

UISplitViewController* splitController = [self.storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"];
UINavigationController* navigationController = [splitController.viewControllers lastObject];
splitController.delegate = (id)navigationController.topViewController;


3. Change rootViewController after login

self.view.window.rootViewController = splitController;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文