简体   繁体   English

SwiftSpinner不再起作用

[英]SwiftSpinner no longer working

I was looking for a way to programmatically set my initial view controller using Storyboards. 我一直在寻找一种使用Storyboards以编程方式设置初始视图控制器的方法。 I found this solution: Programmatically set the initial view controller using Storyboards 我找到了这个解决方案: 使用Storyboards以编程方式设置初始视图控制器

This works just liked I want it to but after using the Swift answer provided in that topic: 这就像我想要的那样工作,但是在使用了该主题中提供的Swift答案之后:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var exampleViewController: ExampleViewController = mainStoryboard.instantiateViewControllerWithIdentifier("ExampleController") as! ExampleViewController

self.window?.rootViewController = exampleViewController

self.window?.makeKeyAndVisible()

return true
}

When loading the view for the first time the framework that used to work won't work anymore: SwiftLoader. 首次加载视图时,以前可以正常工作的框架不再起作用:SwiftLoader。 https://github.com/leoru/SwiftLoader https://github.com/leoru/SwiftLoader

However when I load the same view for the second time the SwiftLoader plugin does activated. 但是,当我第二次加载相同的视图时,SwiftLoader插件确实被激活。

I load SwiftLoader like so: 我像这样加载SwiftLoader:

SwiftLoader.show(title: "Loading...", animated: true)

I've the feeling that it has to do with the code above creating a UIWindow instead of whatever Storyboard used to (UIView?) do but I've no idea as to how to fix this? 我感觉这与上面创建UIWindow的代码有关,而不是与Storyboard以前用来做的任何事情(UIView?)有关,但是我不知道如何解决此问题?

SwiftLoader presents using the application's key window. SwiftLoader使用应用程序的键窗口显示。 See this source code : 参见此源代码

    var currentWindow : UIWindow = UIApplication.sharedApplication().keyWindow!

    // […snip…]

    loader.coverView = UIView(frame: currentWindow.bounds)
    loader.coverView?.backgroundColor = UIColor.clearColor()

    if (loader.superview == nil) {
        currentWindow.addSubview(loader.coverView!)
        currentWindow.addSubview(loader)
        loader.start()
    } else {
        loader.coverView?.removeFromSuperview()
    }

So your problem must be that another window is the key window when you first activate SwiftLoader. 因此,您的问题一定是第一次激活SwiftLoader时另一个窗口是关键窗口。

To check this, inspect UIApplication.sharedApplication().keyWindow and compare it to the UIApplication.sharedApplication().windows array to see what all of the current windows in your app are. 要检查此内容,请检查UIApplication.sharedApplication().keyWindow并将其与UIApplication.sharedApplication().windows数组进行比较,以查看应用程序中所有当前窗口是什么。 The frontmost UIWindow will be the last element of this array. 最前面的UIWindow将是此数组的最后一个元素。

Non-key windows might be iOS keyboards, alert views, etc. 非按键窗口可能是iOS键盘,警报视图等。

I fixed a similar problem in the SVProgressHUD library by implementing this code : 通过实现以下代码解决了SVProgressHUD库中的类似问题:

    NSEnumerator *frontToBackWindows = [UIApplication.sharedApplication.windows reverseObjectEnumerator];
    for (UIWindow *window in frontToBackWindows){
        BOOL windowOnMainScreen = window.screen == UIScreen.mainScreen;
        BOOL windowIsVisible = !window.hidden && window.alpha > 0;
        BOOL windowLevelNormal = window.windowLevel == UIWindowLevelNormal;

        if (windowOnMainScreen && windowIsVisible && windowLevelNormal) {
            [window addSubview:self.overlayView];
            break;
        }
    }

You might want to update SwiftLoader to use smarter logic like this (ported to Swift), or allow you to manually specify a window. 您可能想要更新SwiftLoader以使用像这样的更智能的逻辑(移植到Swift),或者允许您手动指定一个窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM