在app启动时使用故事板和拆分视图控制器正确显示条件登录屏幕? [英] Correctly present conditional login screen at app startup with storyboards and split view controllers?

查看:88
本文介绍了在app启动时使用故事板和拆分视图控制器正确显示条件登录屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这看起来应该很简单,但事实证明它有很多具有挑战性的细微差别 - 而且我还没有在Stack Overflow的其他地方找到答案,这完全,清楚,简单地回答了这个问题。

This seems like it should be simple, but it is proving to have a lot of challenging nuances - and I haven't found an answer elsewhere on Stack Overflow that answers this fully, clearly, and simply.

简而言之 - 我有一个使用故事板来布局应用程序流的iPad应用程序,以及一个拆分视图控制器作为主要根视图控制器。

In a nutshell - I have an iPad application that uses storyboards to layout the application flow, and a split view controller as the primary root view controller.

此应用程序在启动时检查是否存储了登录凭据,如果是,它会直接跳转到UI,如果没有,则会显示全屏登录页面。

This application checks at startup if there are login credentials stored, and if they are it jumps straight to the UI, and if not it presents a full-screen login page.

挑战虽然 - 应该在哪里进行这种有条件的检查,以及如何实例化登录屏幕?

The challenge though - where should this conditional check be made, and how should the login screen been instantiated?

我已经尝试了我能想到的每一种排列。

I have tried every permutation I can think of.

在应用程序委托似乎是显而易见的地方,但调用segues或模态弹出窗口似乎被忽略,因为故事板中的视图尚未生效。

In the app delegate seems like the obvious place, but calling segues or modal popups seem to be ignored because the views from the storyboard are not yet live.

在分割视图的细节控制器的启动方法中,下一个显而易见的地方似乎是。

In the launch methods for the split view's detail controller seems the next obvious place.

我能找到最接近工作的解决方案在此描述:
https://stackoverflow.com/a/8224389/529774

The closest to working solution I can find is described here: https://stackoverflow.com/a/8224389/529774

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"Login"];
    [vc setModalPresentationStyle:UIModalPresentationFullScreen];

    [self presentModalViewController:vc animated:NO];
}

但是这个实现,由拆分视图的详细视图控制器调用,底层分割视图在屏幕上短暂闪烁。

But with this implementation, called by the split view's detail view controller, the underlying split view flashes briefly on the screen.

如果我从viewDidAppear更改为viewWillAppear,则没有闪光 - 但即使屏幕是,登录视图也会以纵向绘制旋转到横向。

If I change from viewDidAppear to viewWillAppear, there is no flash - but the login view ends up drawing in portrait even if the screen is rotated to landscape.

正如我所说 - 这种条件登录显示似乎应该是常见且简单的,但我无法在任何地方找到一个简单的工作示例它结合了拆分视图,故事板,旋转感知,并使UI不闪烁。

As I said - this sort of conditional login display seems like it should be common and easy, but I just can't find a simple working example anywhere that combines a split view, storyboards, rotation awareness, and which keeps the UI from flashing.

任何提示?指向良好工作示例的指针?

Any tips? Pointers to good working examples?

推荐答案

我遇到了完全相同的问题但经过多次搜索后,Duane的回答给了我一些见解。他的回答仍然在前一个视图中闪现,但我通过使用以下方法解决了问题:

I had the exact same problem but after much searching, Duane's answer gave me some insight. His answer still flashes on the previous view but I solved the problem by using:

-(void)viewWillAppear:(BOOL)animated {

    // Check if user is already logged in
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    if ([[prefs objectForKey:@"log"] intValue] == 1) {
        self.view.hidden = YES;
    }
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

    // Check if user is already logged in
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    if ([[prefs objectForKey:@"log"] intValue] == 1) {
        [self performSegueWithIdentifier:@"homeSeg3" sender:self];
    }
}

-(void)viewDidUnload {
    self.view.hidden = NO;
}

这篇关于在app启动时使用故事板和拆分视图控制器正确显示条件登录屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆