Skip to Content
Swift游戏开发经典实例
book

Swift游戏开发经典实例

by Jonathon Manning, Paris Buttfield-Addison
January 2020
Intermediate to advanced
356 pages
6h 4m
Chinese
China Electric Power Press Ltd.
Content preview from Swift游戏开发经典实例
视图和菜单
83
2.13
在游戏内容之上显示菜单
问题
如何将控件和视图覆盖在游戏内容的上层?例如,用一个暂停菜单或
UIButton
象盖在游戏精灵之上。同时,将与暂停菜单有关的
UI
统统放在单独的文件里。
解决方案
我们可以将任何
UIView
覆盖在其他
UIView
的上层。而且,无论
OpenGL
视图还是
Sprite Kit
视图它们都是
UIView
,因此我们也可以在它们上面覆盖其他
UIView
要创建一个能够在屏幕上显示的视图,我们可以新建一个
nib
文件。
nib
文件有点
像故事板,但只能包含单个屏幕或视图。
要新建一个
nib
文件,请依次从菜单中选择
File
New
File
,然后选择
User
Interface
下的
View
。接着为
nib
文件指定一个保存路径。然后就可以在
IB
中编辑
nib
文件和设计我们的
UI
了。
当需要实例化
nib
对象并显示其中的
UI
时,我们需要先创建一个
UINib
对象,然
后通过它从磁盘中加载
nib
对象。通常这会在
viewDidLoad
方法中进行,因为当主
view
被加载之后,这是让你去准备视图内容的第一个机会:
//
从文件中加载一个
nib
let nib = UINib(nibName:
PauseMenu
, bundle: nil)
//
实例化这个
nib
中所包含的对象
let loadedObjects = nib.instantiate(withOwner: self,
options: nil)
nibName
参数必须和
nib
文件名一模一样(不用包含
.xib
扩展名)。 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

精通機器學習

精通機器學習

Aurélien Géron
FreeBSD® Unleashed

FreeBSD® Unleashed

Brian Tiemann, Michael C. Urban
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone
Swift学习手册

Swift学习手册

Jon Manning, Paris Buttfield-Addison, Tim Nugent

Publisher Resources

ISBN: 9787519840129