Sprite Kit中的UIScrollView水平滚动菜单 [英] UIScrollView horizontally scrolling menu in Sprite Kit
问题描述
我正在尝试在新的Sprite Kit游戏中制作一个水平滚动菜单.由于Sprite Kit相当新,因此Sprite Kit的教程不多. UIScrollView是否与Sprite Kit兼容?我已经尝试了几种方法,例如:
I am trying to make a horizontally scrolling menu in my new Sprite Kit game. With Sprite Kit being fairly new, there aren't many good tutorials for Sprite Kit. Is UIScrollView compatible with Sprite Kit? I have tried a couple of ways such as this:
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
NSInteger numberOfViews = 3;
for (int i = 0; i < numberOfViews; i++) {
CGFloat xOrigin = i * self.view.frame.size.width;
UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
[scroll addSubview:awesomeView];
}
这不起作用.我以前从未使用过UIScrollView.任何人都可以使用UIScrollView制作水平滚动菜单的方法吗?我正在尝试做的一个示例是在带有菜单的Bloons TD 5中.
This didn't work. I have never worked with UIScrollView before. Can anyone give a way of making a horizontally scrolling menu using UIScrollView? An example of what I am trying to do is in Bloons TD 5 with their menu.
推荐答案
我知道这个问题已经有几个月了,但是我也正在寻找一个滚动菜单滑块来选择我的SpriteKit游戏中的关卡.我找不到已经存在的任何代码,并且强制将UIScrollView装入我的SpriteKit游戏中的想法对我没有吸引力.因此,我编写了自己的滑动菜单以进行级别选择.
I know this question is a few months old already, but I was also looking for a scrolling menu slider to select levels in my SpriteKit game. I couldn't find any code already existing and the thought of force fitting the UIScrollView into my SpriteKit game didn't appeal to me. So I wrote my own sliding menu for level selection.
我已经模拟了UIScrollView的所有运动,因此它看起来很自然,并且可以配置为向左-向右或向上-向下滚动.
I've simulated all of the motions of the UIScrollView so it looks natural, and can be configured to scroll left - right or up - down.
作为奖励,我在菜单上创建了视差背景,可以轻松地将其替换为新图像以实现自定义外观.
As a bonus I created a parallax background on the menu which can be easily swapped out with new images for a custom look.
https://github.com/hsilived/ScrollingMenu
滚动"菜单的代码注释非常好,因此应该不会出现很多集成问题.
The code for the Scrolling menu is very well commented so there shouldn't be to many integration issues.
github项目有一个完全正常的演示,其中包含Worlds,Levels和视差图像.如果您喜欢,请将我的答案标记为有用,这样我可以赢得一些声誉:)
The github project has a fully working demo with Worlds, Levels and parallax images. If you like it mark my answer as useful so I can gain some reputation :)
这篇关于Sprite Kit中的UIScrollView水平滚动菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!