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游戏开发经典实例
视图和菜单
71
讨论
对游戏
UI
的外观进行定制化最有效的方法是在按钮或其他控件上使用位图,即修
改按钮的
Background
属性。
2
-
19
:切片选项,从左至右分别是水平、垂直、水平 + 垂直
但是,在使用背景图片的时候,你需要小心控件的尺寸:如果图片的宽度为
200
素,而按钮的宽度只有
150
像素,则图片的宽度将会被压缩。相反,背景图片可能
会重复平铺,结果更糟糕。
要解决这个问题,我们可以使用“
slicing
”工具对图片进行切片。你可以将图片分
割成多个区域,其中只有部分区域允许被压缩拉伸或者允许重复。
在这里,我们仅仅用定制按钮来进行演示,但这种方法对其他控件也同样适用。
2.7
UIDynamics
创建动画视图
问题
我们想让视图在屏幕上的运动看起来更加真实。
解决方案
通过
UIDynamicAnimator
,我们可以为
View Controller
中的视图添加物理学行为。
这里,我们假设这个视图叫作
animatedView
。它可以是任何类型,按钮、图片或
者其他。
首先在视图控制器中创建一个
UIDynamicAnimator
对象。在
ViewController
类中
声明一个属性:
72
2
var animator : UIDynamicAnimator?
然后,在
View Controller ...
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