问题
Sample project: https://github.com/wilkinho/RemoveFromParentTest
Swift version: 1.2 Xcode version: 6.3
I try to remove a SKSpriteNode from its parent and add it back to the SKScene within its own SKAction run block (or callback). The result differs in iOS 7.1 and 8.3.
In iOS 7.1, after touching the device, the console prints:
sprite.parent:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})
sprite.scene:nil
sprite2.parent:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})
sprite2.scene:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})
In iOS 8.3, after touching the device, the console prints:
sprite.parent:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})
sprite.scene:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})
sprite2.parent:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})
sprite2.scene:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})
The first SpriteNode lost SKScene reference in iOS 7.1 but not in iOS 8.3. I think this is a bug of Swift 1.2 and I need to workaround it in my project. Any insights will be appreciated.
来源:https://stackoverflow.com/questions/29726606/swift-1-2-bug-different-behavior-between-ios-7-1-and-8-3-while-removing-sksprit