- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在检查用户是否已登录。如果已登录,则跳过 LoginViewController(初始 View Controller ),转到 MainViewController。
我已经尝试在 LoginViewController 生命周期的无数地方进行此检查,而没有底层闪烁。
通过底层闪烁,我的意思是您可以在 MainViewController 出现之前的一瞬间看到 LoginViewController。
我已经解决了这 1 种方法,但感觉非常 hacky:
在我的 LoginViewController 中:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
calls++
if calls == 2 && NSUserDefaults.standardUserDefaults().objectForKey("AuthToken") != nil {
self.performSegueWithIdentifier("loginUserNoAnim", sender: self)
}
}
“loginUserNoAnim”是我创建的没有动画的自定义 Segue。
viewDidLayoutSubviews()
在我的代码中被调用 3 次。前两次,我收到警告说我的 ViewController 不在类似于此的窗口层次结构中:Warning: Attempt to present <PSLoginViewController: 0x1fda2b40> on <PSViewController: 0x1fda0720> whose view is not in the window hierarchy!
这会在 UI 中创建两个非常快速的白色闪烁。我通过检查通过 call
调用了多少电话来摆脱了它们变量。
现在,这是 100% 的 hacky,是 Not Acceptable 。
有没有办法通过使用 iOS 生命周期来解决这个问题?我什至尝试过使用 appdelegate 方法:
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
但我还是看到了下层闪光。缓解它的最佳方法是什么?
最佳答案
我认为以下 StackOverflow 答案很好地解释了如何在应用程序启动时在登录和主视图 Controller 之间切换:
Programmatically set the initial view controller using Storyboards
请注意,如果您在应用程序中提供注销功能,那么您应该将用户引导至登录 View Controller ,因为它仅在应用程序启动时被检查。
关于ios - 在没有底层 flash 的情况下,如何在 View 出现之前执行 Segue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28425527/
我是一名优秀的程序员,十分优秀!