Sprite Kit 中的 UIScrollView 水平滚动菜单 [英] UIScrollView horizontally scrolling menu in Sprite Kit

查看:17
本文介绍了Sprite Kit 中的 UIScrollView 水平滚动菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的新 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 项目有一个完整的演示,包含世界、关卡和视差图像.如果您喜欢,请将我的回答标记为有用,这样我就可以获得一些声誉:)

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆