简体   繁体   English

SpriteKit SKView 不再在场景之间转换 iOS 9

[英]SpriteKit SKView no longer transitions between scenes in iOS 9

We have a code base that was written and released in 2013, but in iOS 9 the app no longer transitions visibly between SKScene s when the presentScene:transition: message is sent to our SKView .我们有一个代码库是在 2013 年编写和发布的,但是在 iOS 9 中,当presentScene:transition:消息发送到我们的SKView时,应用程序不再在SKScene之间明显转换。 The SKScene receives the didMoveToView: message but the scene itself never shows on screen. SKScene收到didMoveToView:消息,但场景本身从未显示在屏幕上。

Here's what we tried:这是我们尝试过的:

  • Disabling Metal via the Info.plist通过Info.plist禁用Metal
  • Using [SKTransition transitionWithCIFilter:duration:] instead of the predefined animations使用[SKTransition transitionWithCIFilter:duration:]而不是预定义的动画
  • Tweaking zPosition调整zPosition
  • Switching to regular UIView animations (this made our SKNode s disappear)切换到常规UIView动画(这使我们的SKNode消失了)
  • Making sure the transition method doesn't get called more than once确保过渡方法不会被多次调用
  • Explicitly setting pausesOutgoingScene to YES on the SKTransitionSKTransition上明确设置pausesOutgoingSceneYES

None of the above attempts fixed the issue.上述尝试均未解决该问题。 Note that everything transitions properly in iOS 8请注意,一切都在 iOS 8 中正确转换

Here is some sample code that doesn't work:这是一些不起作用的示例代码:

-(BOOL)presentTitle {
    if (!titleSceneLoaded) {
        return NO;
    }
    [skView presentScene:titleScene transition:[SKTransition fadeWithDuration:1.0]];
    return YES;
}

Changing it to this makes it work again (without the transitions):将其更改为此使其再次工作(没有转换):

-(BOOL)presentTitle {
    if (!titleSceneLoaded) {
        return NO;
    }
    [skView presentScene:titleScene];
    return YES;
}

Any suggestions on how to locate/fix/workaround the bug?关于如何定位/修复/解决错误的任何建议?

There is a bug in iOS9 with presenting a scene with a transition in a subview. iOS9中存在一个错误,它在子视图中显示一个带有转换的场景。

I had the same issue and in my controller I was able to fix the issue by changing the following code in viewWillLayoutSubviews from this: 我有同样的问题,在我的控制器中,我能够通过更改viewWillLayoutSubviews中的以下代码来解决此问题:

        [self.subview presentScene:self.scene];
        [self.view addSubview:self.subview];

to this: 对此:

        [((SKView *)self.view) presentScene:self.scene];

Another workaround if the scene has to remain in a subview approach is to use presentScene without the transition, which does work. 如果场景必须保持在子视图方法中,另一种解决方法是使用presentScene而不进行转换,这确实有效。

We were unable to get SKTransition to work. 我们无法让SKTransition工作。 We talked to the developer support team, posted on the developer forums, and tried everything posted here. 我们与在开发人员论坛上发布的开发人员支持团队进行了交谈,并尝试了在此发布的所有内容。

It is SpriteKit bug exclusive to iOS 9. If anyone else runs into this bug on iOS 9, we switched to custom transitions utilizing UIView animateWithDuration:animations:completion: . 它是iOS 9独有的SpriteKit bug。如果其他人在iOS 9上遇到这个bug,我们使用UIView animateWithDuration:animations:completion:切换到自定义转换UIView animateWithDuration:animations:completion:

It is a bit late but my own wrestling with what seems to be this bug may be worth exploring.有点晚了,但我自己与这个错误的斗争可能值得探索。

As I found out, I had a UIViewController floating around without having being fully deallocated, which had an SKView on it.正如我发现的那样,我有一个 UIViewController 在没有被完全释放的情况下四处漂浮,上面有一个 SKView。

The only side-effect from that SKView still being somewhat live was the presentScene(transition) not working, as you have experienced. SKView 仍然存在的唯一副作用是presentScene(transition)不起作用,正如您所经历的那样。

It will work if you drag and drop the SKView in the storyboard instead of creating it manually .如果您将 SKView 拖放到 storyboard而不是手动创建它,它将起作用。 在此处输入图像描述

Then in the ViewController, create an outlet:然后在 ViewController 中,创建一个插座:

@IBOutlet var skView: SKView!

Then present the scene as:然后将场景呈现为:

homeScene = HomeScene(size: self.view.frame.size)
homeScene.scaleMode = .aspectFill
homeScene.backgroundColor = .clear
skView.presentScene(homeScene)

And from this SKScene, you can simply use the navigation with the transition as:从这个 SKScene 中,您可以简单地使用带有过渡的导航:

let gameScene = GameScene(size: self.size) 
self.view?.presentScene(gameScene, transition: SKTransition.doorsOpenHorizontal(withDuration: 1))

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

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