ios - 意外的零窗口(空白黑屏)

标签 ios xcode swift google-maps parse-platform

如果有人能找到正确的副本,请将其链接给我,我将不胜感激,但我的情况与同样有错误的人有点不同。我的具体问题是,一旦模拟器打开我的应用程序,只有一个空白的黑屏,没有错误发生或没有任何加载,直到我点击屏幕导致以下错误。

编辑:我已经注释掉了代码中的所有内容,但它仍然收到此错误,并且创建了一个新的 main.storyboard,仍然没有解决方案...

unexpected nil window in _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow: <UIClassicWindow: 0x7f9f3a445190; frame = (0 0; 414 736); userInteractionEnabled = NO; gestureRecognizers = <NSArray: 0x7f9f3a510ed0>; layer = <UIWindowLayer: 0x7f9f3a4077d0>>

据我所知,我没有更改任何代码,所以下面是我的整个 View Controller ,然后是我的应用程序委托(delegate)

View Controller :

import UIKit
import GoogleMaps
import Parse
import MediaPlayer
import MobileCoreServices


class ViewController: UIViewController {
@IBOutlet weak var viewMap: GMSMapView!



override func viewDidLoad() {
    super.viewDidLoad()

    let testObject = PFObject(className: "TestObject")
    testObject["foo"] = "bar"
    testObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
        print("Object has been saved.")
    }

    let camera = GMSCameraPosition.cameraWithLatitude(33.600727, longitude: -117.900840, zoom: 16.9)


    viewMap.camera = camera
    viewMap.myLocationEnabled = true
    viewMap.settings.myLocationButton = true


    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2DMake(33.600727, -117.900840)
    marker.title = "Newport Beach"
    marker.snippet = "California"
    marker.map = viewMap

    // Do any additional setup after loading the view, typically from a nib.
    let button   = UIButton(type: UIButtonType.System) as UIButton
    button.frame = CGRectMake(100, 100, 100, 50)
    button.setTitle("Test Button", forState: UIControlState.Normal)
    button.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)

    self.view.addSubview(button)
    Upload()
}



func Upload() {
var path = NSBundle.mainBundle().pathForResource("/Users/matthewcarlson/Downloads/big_buck_bunny_720p_2mb.mp4", ofType: "mp4")
var videodata: NSData?
videodata = NSData.dataWithContentsOfMappedFile(path!) as? NSData


let file = PFFile(name:"resume.txt", data:videodata!)
file!.saveInBackground()

}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func snapNext(sender: AnyObject) {
    let newLocation = GMSCameraPosition.cameraWithLatitude(33.622578, longitude: -117.911099, zoom: 16.9)
    viewMap.camera = newLocation



}

func buttonAction(sender:UIButton!)
{
    print("Button tapped")

}
}

应用委托(delegate):

import UIKit
import GoogleMaps
import Parse
import Bolts

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    // Initialize Parse.
    let configuration = ParseClientConfiguration {
        $0.applicationId = "w4hfIKBxy5uHc9eHQ3GavJ4vT9qyJBzKoO66pyM5"
        $0.clientKey = "jsZ8pfx6FfIVMlLUYvZ6MAdnBIltMiae5TgZWW9o"
        $0.server = "https://parseapi.back4app.com/"
    }
    Parse.initializeWithConfiguration(configuration)

    //initialize GoogleMaps
    GMSServices.provideAPIKey("AIzaSyDClpTwyY3swY2rlLKejd1pCVurTkVuNGg")
    return true



}

func applicationWillResignActive(application: UIApplication) {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

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.
}

func applicationWillTerminate(application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

非常感谢任何帮助我已经清理了构建,再次运行它,并强制退出 Xcode 和模拟器,到目前为止没有任何效果。

最佳答案

尝试以下解决方法:

  • 在实例化 UIWindow 之前设置状态栏方向。

    (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Init my stuff
        // ...
        // Prepare window
    [application setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO]; // prevent start orientation bug
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window makeKeyAndVisible];
    return YES;
    
  • 在我的主 xib 中将窗口的“隐藏”设置为"is"。

  • 在窗口从 Root View Controller 获取方向后设置框架。
  • 打开主 xib 文件并从左侧找到“窗口”并启用启动时可见启动时全屏
  • 检查您的 Window nib 文件并确保它占据了整个屏幕。

检查这些相关问题:

关于ios - 意外的零窗口(空白黑屏),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37377792/

相关文章:

ios - 如何使用 UIWebView Delegate 的 shouldStartLoadWithRequest 方法

c++ - Xcode STL C++调试编译报错

iphone - Leaks Instrument 中的颜色和百分比表示什么?

ios - 在模拟器中使用 Firebase 尝试从照片库上传图像时出现 Swift 4 错误

ios - 如何监听同一 View 中不同控件上的点击手势?

swift - Xcode 错误 : building for iOS Simulator, 但在为 iOS 构建的目标文件中链接

ios - iOS 的 BLE 外设名称不正确

ios - 模拟器在第二次运行时显示黑屏

ios - 有没有办法使用私有(private) API 在 iOS 上自行卸载应用程序?

ios - iOS 无法设置 UIView 的底部阴影?