我目前的登录流程有问题。逻辑就在那里,但是从登录 View 到主视图的动画很奇怪。
边注:主视图是一个带有 5 个 UINavigationControllers
的 UITabBarController
,登录 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 现在显示了一个很好的过渡...然后当我尝试登录时,一切正常,但是当过渡发生时登录->主视图,整个主视图(位置除外UITabBarController
的 UITabBar
基本上暂时设置为 -20px,然后重置为预期位置...这是登录转换时的两个屏幕截图到主视图,然后当它完成转换时......
我已经在没有 UITabBarController 的情况下测试了这个确切的实现,但它没有这样做。这有点 GLITCH 问题。任何人都可以传递任何想法?
我想知道是否可以在不必实现主程序的 viewDidAppear
或 viewWillAppear
方法的情况下执行此登录->主和主-> 登录转换。
例如,在主视图中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/