ios - 将 UIWindow rootViewController 从 UIViewController 重新分配给包含 UINavigationControllers 的 UITabBarController

标签 ios objective-c parsing uitabbarcontroller uiwindow

我目前的登录流程有问题。逻辑就在那里,但是从登录 View 到主视图的动画很奇怪。

边注:主视图是一个带有 5 个 UINavigationControllersUITabBarController,登录 View 只是一个 UIViewController

所以首先我在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中确定当前用户是否已经登录(我正在使用 Parse 来处理),如果他们没有,则将 UIWindows rootViewController 设置为登录 Controller 。否则,将 UIWindows rootViewController 设置为主视图。

这工作正常...假设用户在应用程序启动时登录。好的,它显示了主视图。然后我注销,一切都按预期进行。我通过运行此方法切换 UIWindows rootViewController:

- (void)showLogin {
    self.activity = nil;
    self.chat = nil;
    self.create = nil;
    self.notification = nil;
    self.more = nil;

    self.loginViewController = nil; 
    if (!self.loginViewController) { // this check is redundant i feel lol
        self.loginViewController = [[PHLoginRegisterViewController alloc] init];
    }

    [UIView transitionWithView:self.window
                      duration:0.5
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{
                        self.window.rootViewController = self.loginViewController;
                    } completion:^(BOOL finished) {
                        self.activity = [[PHActivityViewController alloc] init];
                        self.chat = [[PHGlobalChatViewController alloc] init];
                        self.notification = [[PHNotificationsViewController alloc] init];
                        self.more = [[PHMoreViewController alloc] init];
                        [self.tabBarController setViewControllers:@[[[UINavigationController alloc] initWithRootViewController:self.activity],
                                                                    [[UINavigationController alloc] initWithRootViewController:self.chat],
                                                                    [[UINavigationController alloc] init],
                                                                    [[UINavigationController alloc] initWithRootViewController:self.notification],
                                                                    [[UINavigationController alloc] initWithRootViewController:self.more]]];
                        [self.tabBarController setSelectedIndex:0];
                    }];
}

好的,所以登录 View 现在显示了一个很好的过渡...然后当我尝试登录时,一切正常,但是当过渡发生时登录->主视图,整个主视图(位置除外UITabBarControllerUITabBar 基本上暂时设置为 -20px,然后重置为预期位置...这是登录转换时的两个屏幕截图到主视图,然后当它完成转换时...... During Transition After Transition

我已经在没有 UITabBarController 的情况下测试了这个确切的实现,但它没有这样做。这有点 GLITCH 问题。任何人都可以传递任何想法?

我想知道是否可以在不必实现主程序的 viewDidAppearviewWillAppear 方法的情况下执行此登录->主和主-> 登录转换。

例如,在主视图中viewDidAppear

if (user is logged in)

        [self presentViewController:login animated:NO]

这会导致在显示登录 View 之前先看到主屏幕一小段时间,这是我不希望看到的。

最佳答案

我认为问题是在你的转换完成之前,自动布局过程没有被触发,所以你的 View 是它在你的 xib 设计中的位置。

我有一个解决这个问题的想法,每当应用程序启动时,您都将主视图 Controller 用作 Root View Controller ,如果您需要登录,则在主视图 Controller 的 viewDidLoad 中加载登录 View Controller 并添加它是主视图 Controller 的顶级 subview ,这将解决演示文稿的问题。

唯一的缺点是您的登录 View 需要不透明的背景。

关于ios - 将 UIWindow rootViewController 从 UIViewController 重新分配给包含 UINavigationControllers 的 UITabBarController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28339822/

相关文章:

objective-c - NSTextView 滚动行为和选择行为

c# - 在 Set 方法中解析

带有 Tabbar 的 iOS7 自动布局与 UIScrollView 和可缩放的 UIImageView 不工作

ios - 如何比较 Objective-c 中的各种 NSArray?

objective-c - iOS 和 OS X 开发的内置框架中是否有任何非前缀类?

Java SimpleDateFormat 解析奇怪的结果

jquery - 为什么我的 jQuery 在使用它之前没有正确解析数据元素中的 JSON

iphone - 在有限的边界内拖动 View 而不超出该边界

ios - 未为 whatsapp 事件调用 UIActivityViewController setCompletionWithItemsHandler

objective-c - 定义 NSMutableString?