0

我有一个 UIImageView 供用户查看(看起来几乎像启动屏幕),以便我可以预加载我的纹理图集。

但似乎在完成块中,即使我说'removefromsuperview'它也没有这样做。

我知道纹理已经完成加载,因为如果我点击屏幕 UIImageView 消失并且我的游戏开始了,但由于某些奇怪的原因它不会自行消失。

这是我的 GameViewController 中的 viewDidLoad:

//Configure the View
    let skView = view as! SKView

    skView.multipleTouchEnabled = false
    self.view.exclusiveTouch = false

    //Create and Configure the scene
    scene = GameScene(size: skView.bounds.size)

    scene.scaleMode = .AspectFill

    //Load "SPLASH SCREEN"
    let image: UIImage = UIImage(named: "ViewControllerImage")!
    GameViewController.splashView = UIImageView(image: image)
    GameViewController.splashView!.frame = CGRectMake(0,0,self.view.bounds.width,self.view.bounds.height)
    self.view.addSubview(GameViewController.splashView!)




SKTextureAtlas.preloadTextureAtlases([GameViewController.diploTextureAtlas,GameViewController.bieberTextureAtlas,GameViewController.skrillexTextureAtlas,GameViewController.sunTextureAtlas], withCompletionHandler: { () -> Void in

        print("Completo")
        GameViewController.splashView?.removeFromSuperview()
        skView.presentScene(self.scene)

    })
4

1 回答 1

0

试试这个代码:

//Configure the View
    let skView = view as! SKView

    skView.multipleTouchEnabled = false
    self.view.exclusiveTouch = false

    //Create and Configure the scene
    scene = GameScene(size: skView.bounds.size)

    scene.scaleMode = .AspectFill

    //Load "SPLASH SCREEN"
    let image: UIImage = UIImage(named: "ViewControllerImage")!
    GameViewController.splashView = UIImageView(image: image)
    GameViewController.splashView.tag = 666
    GameViewController.splashView!.frame = CGRectMake(0,0,self.view.bounds.width,self.view.bounds.height)
    self.view.addSubview(GameViewController.splashView!)




SKTextureAtlas.preloadTextureAtlases([GameViewController.diploTextureAtlas,GameViewController.bieberTextureAtlas,GameViewController.skrillexTextureAtlas,GameViewController.sunTextureAtlas], withCompletionHandler: { () -> Void in

        print("Completo")
        for view in self.view!.subviews {
            if view.tag == 666 {
               view.removeFromSuperview()
            }
        }
        skView.presentScene(self.scene)

    })

您也可以使用以下方法更改循环:

if let viewWithTag = self.view.viewWithTag(666) {
        viewWithTag.removeFromSuperview()
}
于 2016-04-13T09:26:52.580 回答