gpt4 book ai didi

ios - SpriteKit,Swift - ScrollView 未显示

转载 作者:行者123 更新时间:2023-11-30 13:47:55 27 4
gpt4 key购买 nike

好吧,我用这个方法实现了一个 ScrollView :

How to create a vertical scrolling menu in spritekit?

现在,当我启动场景时,除了黑色/灰色背景之外,它不会显示任何内容

这是我在菜单场景中使用的代码:

import Foundation
import SpriteKit
import UIKit

//let kMargin: CGFloat = 40

//var backButton = SKSpriteNode()
//var selectButton = SKSpriteNode()
var moveableNode = SKNode()
var scrollView: CustomScrollView!
private var imageSize = CGSize.zero

var sprite = SKSpriteNode()

class Menu: SKScene {

func didMoveToView() {

addChild(moveableNode)

scrollView = CustomScrollView(frame: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height), scene: self, moveableNode: moveableNode)
scrollView.contentSize = CGSizeMake(self.frame.size.width, self.frame.size.height * 2)
view!.addSubview(scrollView)

sprite = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 44))
sprite.position.y = CGRectGetMidY(self.frame) + self.frame.size.height
moveableNode.addChild(sprite)

}

}

这可能很明显,但我似乎看不到。

最佳答案

尝试这个 Sprite ,我在另一个问题中犯了一个错误,它应该是 - self.frame.size.height,而不是+。

 sprite = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 44))
sprite.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame) - self.frame.size.height)
moveableNode.addChild(sprite)

检查我的 gitHub 项目

https://github.com/crashoverride777/Swift-2-SpriteKit-UIScrollView-Helper

关于ios - SpriteKit,Swift - ScrollView 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34696794/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com