找到你要的答案

Q:SwiftSpinner no longer working

Q:swiftspinner不再工作

I was looking for a way to programmatically set my initial view controller using Storyboards. I found this solution: Programatically set the initial view controller using Storyboards

This works just liked I want it to but after using the Swift answer provided in that topic:

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. https://github.com/leoru/SwiftLoader

However when I load the same view for the second time the SwiftLoader plugin does activated.

I load SwiftLoader like so:

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?

我在寻找一种以编程方式设置我的初始视图控制器使用故事板。我发现这样的解决方案:通过程序设置初始视图控制器使用故事板

这作品只是喜欢我想它,但使用后,在该主题提供了快速的答案:

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
}

当加载视图首次用于工作不会再工作的框架:SwiftLoader。https://github.com/leoru/swiftloader

然而当我负载相同观点,第二次swiftloader插件并激活。

我喜欢这样swiftloader负荷:

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

我觉得这跟上面创建一个UIWindow代替任何脚本用于代码(UIView?)但我不知道如何解决这个问题?

answer1: 回答1:

SwiftLoader presents using the application's key window. 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.

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. The frontmost UIWindow will be the last element of this array.

Non-key windows might be iOS keyboards, alert views, etc.

I fixed a similar problem in the SVProgressHUD library by implementing this code:

    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提出使用应用程序的关键窗口。看到这个源代码:

    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()
    }

所以你的问题一定是另一个亮点是关键的窗口,当你第一次启动swiftloader。

检查,检查程序。sharedapplication()。keywindow和比较它的程序。sharedapplication()。Windows阵看你应用程序中的所有当前的Windows是什么。最前面的一个UIWindow将这个数组最后一个元素。

非关键的Windows可能是iOS键盘、报警视图等。

我固定在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;
        }
    }

你可能要更新swiftloader使用聪明逻辑这样(移植到斯威夫特),或允许你手动指定窗口。

ios  swift