Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift 2.0,SpriteKit-滚动查看以不使用页面。_Ios_Swift_Uiscrollview_Sprite Kit - Fatal编程技术网

Ios Swift 2.0,SpriteKit-滚动查看以不使用页面。

Ios Swift 2.0,SpriteKit-滚动查看以不使用页面。,ios,swift,uiscrollview,sprite-kit,Ios,Swift,Uiscrollview,Sprite Kit,好的,我有一个scrollView,它已经被子类化,可以应用到任何场景,这是我在这里问的前一个问题: 导入基础 进口SpriteKit ///接触节点 var nodesTouched:[AnyObject]=[]//全局 ///滚动方向 枚举滚动方向:Int{ 案例无=0 垂直箱 案例水平 } 类CustomScrollView:UIScrollView{ //标记:-静态属性 ///允许触摸 静态变量disabledTouches=false ///滚动视图 私有静态变量scrollVie

好的,我有一个scrollView,它已经被子类化,可以应用到任何场景,这是我在这里问的前一个问题:

<代码>导入基础 进口SpriteKit ///接触节点 var nodesTouched:[AnyObject]=[]//全局 ///滚动方向 枚举滚动方向:Int{ 案例无=0 垂直箱 案例水平 } 类CustomScrollView:UIScrollView{ //标记:-静态属性 ///允许触摸 静态变量disabledTouches=false ///滚动视图 私有静态变量scrollView:UIScrollView! //标记:-属性 ///当前场景 私人弱电场景:SKScene? ///可移动节点 私有var moveableNode:SKNode? ///滚动方向 private var scrollDirection=scrollDirection.None //MARK:-Init init(帧:CGRect,场景:SKScene,moveableNode:SKNode,scrollDirection:scrollDirection){ 打印(“滚动视图初始化”) super.init(frame:frame) CustomScrollView.scrollView=self self.scrollDirection=滚动方向 self.currentsecene=场景 self.moveableNode=moveableNode self.frame=frame 指示符号样式=.White scrollEnabled=true //self.minimumZoomScale=1 //self.maximumZoomScale=3 canCancelContentTouches=错误 userInteractionEnabled=true 代表=自我 //spritekit翻盖(仅用于水平) 如果self.scrollDirection==水平{ 设flip=CGAffineTransformMakeScale(-1,-1) self.transform=flip } } 必需的初始化?(编码器aDecoder:NSCoder){ fatalError(“初始化(编码者:)尚未实现”) } } //马克:触摸 扩展自定义滚动视图{ ///开始 覆盖功能触摸开始(触摸:设置,withEvent事件:UIEvent?){ 打印(“触摸开始滚动视图”) guard!CustomScrollView.disabledTouches else{return} currentScene?.touches开始(Touchs,withEvent:event) } ///移动 覆盖功能触摸移动(触摸:设置,带事件:UIEvent?){ 打印(“触摸移动滚动视图”) guard!CustomScrollView.disabledTouches else{return} currentScene?.touchesMoved(触摸,withEvent:event) } ///结束 覆盖func touchesEnded(触摸:设置,withEvent事件:UIEvent?){ 打印(“触摸结束滚动视图”) guard!CustomScrollView.disabledTouches else{return} currentScene?.touchesEnded(触摸,withEvent:event) } ///取消 覆盖功能触摸已取消(触摸:设置?,带事件:UIEvent?){ 打印(“触摸取消滚动视图”) guard!CustomScrollView.disabledTouches else{return} currentScene?.touchesCancelled(触摸,withEvent:event) } } //标记:-触摸控制 扩展自定义滚动视图{ ///禁用 类func disable(){ 打印(“禁用滚动视图”) CustomScrollView.scrollView?.userInteractionEnabled=false CustomScrollView.disabledTouches=true } ///使能 类func enable(){ 打印(“已启用的滚动视图”) CustomScrollView.scrollView?.userInteractionEnabled=true CustomScrollView.disabledTouches=false } } //马克:-各位代表 扩展CustomScrollView:UIScrollViewDelegate{ ///卷轴 func scrollViewDidScroll(scrollView:UIScrollView){ 打印(“滚动视图已滚动”) 如果滚动方向==水平{ moveableNode!.position.x=scrollView.contentOffset.x }否则{ moveableNode!.position.y=scrollView.contentOffset.y } } } 唯一的问题是scrollview使用页面,而按照我希望的方式,它只在精灵中滚动,就像raywenderlich一样,所有精灵都是唯一移动的东西,因此我不必滚动多个页面才能找到精灵

可在以下位置找到该项目:


因为他们使用他们的gameViewController,所以我很难弄清楚如何通过上面提到的scrollview子类实现它。

我不明白你在问什么。我刚刚查看了RayWenderlich教程,它与我的GitHub示例项目完全相同。他们只是让精灵靠得更近,就像在我的项目中为了演示的目的,我把每个精灵放在一个新的页面上

如果只希望精灵滚动,只需将精灵添加到moveableNode,其余的则像往常一样直接添加到场景中

addChild(background)
moveableNode.addChild(sprite1)
而不是改变精灵的位置,使它们更靠近。基本上,您将第一个精灵添加到scrollView的第一页,然后根据之前的精灵x位置定位其他精灵。您也可以将这些精灵添加到精灵1中

let sprite1 = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 50))
sprite1.position = CGPointMake(0, 0)
page1ScrollView.addChild(sprite1)

let sprite2 = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 50))
sprite2.position = CGPointMake(sprite1.position.x + (sprite2.size.width * 1.5), sprite1.position.y)
sprite1.addChild(sprite2)

let sprite3 = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 50))
sprite3.position = CGPointMake(sprite2.position.x + (sprite3.size.width * 1.5), sprite1.position.y)
sprite1.addChild(sprite3)
我更新了我的gitHub项目,以显示这一点
我不明白你在问什么。我刚刚查看了RayWenderlich教程,它与我的GitHub示例项目完全相同。他们只是让精灵靠得更近,就像在我的项目中为了演示的目的,我把每个精灵放在一个新的页面上

如果只希望精灵滚动,只需将精灵添加到moveableNode,其余的则像往常一样直接添加到场景中

addChild(background)
moveableNode.addChild(sprite1)
而不是改变精灵的位置,使它们更靠近。基本上,您将第一个精灵添加到scrollView的第一页,然后根据之前的精灵x位置定位其他精灵。您也可以将这些精灵添加到精灵1中

let sprite1 = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 50))
sprite1.position = CGPointMake(0, 0)
page1ScrollView.addChild(sprite1)

let sprite2 = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 50))
sprite2.position = CGPointMake(sprite1.position.x + (sprite2.size.width * 1.5), sprite1.position.y)
sprite1.addChild(sprite2)

let sprite3 = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 50))
sprite3.position = CGPointMake(sprite2.position.x + (sprite3.size.width * 1.5), sprite1.position.y)
sprite1.addChild(sprite3)
我更新了我的gitHub项目,以显示这一点

我刚刚尝试了您上面所说的,但是sprite1之后的精灵没有对齐,它们只是屏幕底部的一半。另外,我根本看不到第三个。我刚刚更新了我的答案,你需要将精灵2,3等添加到精灵1“sprite1.addChild(sprite2)…”。只需再次复制上面更新的代码,看看它现在是否可以工作,在完成滚动后,是否可以锁定到一个精灵,而不是半开半关?就像ray项目一样。(我应该再问一个问题吗?)如果是的话,我明天再问。是的,最好提出一个新问题。我也很乐意帮你做新的。我还更新了我的an