Skip to Content
Swift学习手册
book

Swift学习手册

by Jon Manning, Paris Buttfield-Addison, Tim Nugent
February 2017
Beginner to intermediate
472 pages
9h 53m
Chinese
China Electric Power Press Ltd.
Content preview from Swift学习手册
图像和删除
277
这段代码做了很多事。首先,询问
UIImagePickerController
类有没有可用的相机。
如果没有(在
iOS
模拟器中),那就没有必要提供“相机”这个选项。
在设备中运行应用
如果你还未在设备中运行应用,现在是个好时机。为此,要登录
iOS
开发者账户:
打开“
Xcode
”菜单,选择“
Preferences
”,打开“
Accounts
”选项卡,添加你的
Apple ID
。登录后,使用
USB
线缆把你的设备连接到电脑上,然后在
Xcode
左上角
打开方案选择菜单。选择你的设备,然后单击运行按钮。
Xcode
会编译应用,然后
把它安装到你的设备中。
然后,创建一个变量,保存用户轻点“
Camera
”选项后执行的动作。这个变量保存
的代码取决于用户有没有授权访问相机。如果应用有权访问,或者用户尚未决定,
那么这个闭包调
addPhoto
方法,呈现
UIImagePickerController
。图像拾取器出
现后,如果没有权限,会请求用户授权。
如果用户尚未授权,不能呈现图像拾取器控制器。如果呈现,图像拾取器不会再次
请求授权,因此用户会看到一个无用的黑色界面。我们不这么做,而是显示一个对
话框,说明情况。这个对话框中有一个动作,轻点后会把用户带到设置页面,让用
户授权应用访问相机。
前面说过,可以扩展这个功能,支持使用相簿中的照片。
6.
运行应用。现在你可以为文档添加图像,添加的图像会出现在附件列表中。
11.3
查看附件
附件有多种类型,每种类型都重复编写“查看视图控制器”有点不现实。我们将为每种
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

PyTorch深度学习

PyTorch深度学习

Posts & Telecom Press, Vishnu Subramanian
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone
PHP学习手册

PHP学习手册

David Sklar
C语言核心技术(原书第2版)

C语言核心技术(原书第2版)

Peter Prinz, Tony Crawford

Publisher Resources

ISBN: 9787519803223