Skip to content

Commit eeb7058

Browse files
committed
去掉原文
1 parent 2499d0f commit eeb7058

File tree

1 file changed

+9
-88
lines changed

1 file changed

+9
-88
lines changed
Lines changed: 9 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,49 @@
11
# Swift视频录制开发指南
2-
======================================================
2+
===
33

44
> * 原文链接 : [Take Video Tutorial in iOS8 with Swift](http://www.ioscreator.com/tutorials/take-video-tutorial-ios8-swift)
55
* 原文作者 : [ioscreator](www.ioscreator.com)
66
* [译文出自 : 开发技术前线 www.devtf.cn](http://www.devtf.cn)
77
* 译者 : [Mr.Simple](https://github.com/bboyfeiyu)
8-
* 校对者: []()
9-
10-
Apple provides the UIImagePickerController which is an user interface to
11-
take videos using the built-in camera of an iOS device. In this tutorial
12-
we will take a video which will be saved in the Photo Library of the
13-
device. This tutorial is built in iOS 8.4 and Xcode 6.4。
8+
* 校对者: [StormXX](https://github.com/StormXX)
149

1510
Apple提供了一个UIImagePickerController用户界面类来让用户使用内置的摄像头来拍摄视频。我的开发环境是iOS 8.4和xcode 6.4,在这篇文章中我会教大家获取已经存储在Photo Library的视频。
1611

17-
Open Xcode and create a new Single View Application. For product name,
18-
use **IOS8SwiftTakeVideoPlayerTutorial** and then fill out the
19-
Organization Name and Organization Identifier with your customary
20-
values. Enter Swift as Language and make sure only iPhone is selected in
21-
Devices.
22-
2312
首先打开Xcode,然后创建一个名为IOS8SwiftTakeVideoPlayerTutorial的应用,Organization名和Organization标识符使用你自己的即可。选择Swift作为开发语言,并且该应用只支持Iphone。
2413

2514
![](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/559ce50ee4b0560c42b45099/1436345615076/)
2615

27-
Go to the **Storyboard** and drag two buttons from the Object Library to
28-
the main view. Give the buttons a title of "Take Video" and "View
29-
Library". The storyboard should look like this.
30-
3116
到Storyboard页面,从Object Library拖两个按钮到主视图上,给这两个按钮设置title,分别为"Take Video" 和 "View Library",Storyboard此时应该如下图所示:
3217

3318
![](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/559ce595e4b0cebfa4eee243/1436345750826/)
3419

35-
Hold down the Ctrl key and select both buttons. Click the "Resolve Auto
36-
Layout Issues" button on the bottom-right of the Storyboard and select
37-
"Add Missing Constraints".
38-
3920
按住Ctrl键,然后选中这两个按钮,点击在Storyboard右下方的“Resolve Auto Layout Issues”按钮,然后选择“Add Missing Constraints”。如下图所示 :
4021

41-
4222
![](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/559ce604e4b04c3e89ff0e2e/1436345862940/)
4323

44-
45-
Select the Assistant Editor and make sure
46-
the **ViewController.swift** is visible. Ctrl and drag from the top
47-
Button and create the following Action.
48-
4924
切换到Assistant Editor界面,并且确保ViewController.swift是可见的。按住Ctrl并从Take Video按钮区域拖出以创建一个Action.
5025

5126
![](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/559ce655e4b051cc74e74388/1436345942333/)
5227

53-
54-
Ctrl and drag from the bottom Button and create the following Action.
55-
5628
同样的,按住按住Ctrl并从View Library按钮区域拖出以创建一个Action。
5729

58-
5930
![](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/559ce67fe4b001bba4e7e8e9/1436345984380/)
6031

61-
62-
Go to the ViewController.swfit file and add the following lines at the
63-
top off the file.
64-
6532
切换到ViewController.swfit文件,在文件的头部添加如下代码。
6633

67-
68-
```swift
34+
```
6935
import MobileCoreServices
7036
import AssetsLibrary
7137
```
7238

73-
74-
Change the ViewController class declaration line to
75-
7639
修改ViewController类的定义如下 :
7740

78-
79-
```swift
80-
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
81-
```
82-
83-
These delegates are needed to let the ViewController handle the
84-
UIImagePickerController delegation. Implement the **takeVideo** method
41+
`class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
42+
`
8543

8644
这些delegates使得ViewController能够处理UIImagePickerController的代理事件,takeVideo的实现如下 :
8745

88-
```swift
46+
```
8947
@IBAction func takeVideo(sender: AnyObject) {
9048
// 1 Check if project runs on a device with camera available
9149
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
@@ -104,22 +62,12 @@ UIImagePickerController delegation. Implement the **takeVideo** method
10462
}
10563
```
10664

107-
108-
1. The isSourceTypeAvailable method checks if the device supports the
109-
Camera sourceType
110-
2. An ImagePickerController is displayed using the Camera Sourcetype
111-
and the Movie mediaType. The maximum length of a movie is set to 10
112-
seconds,
113-
11465
1. isSourceTypeAvailable函数是检测设备的Camera是否可用;
11566
2. ImagePickerController用于显示Sourcetype为Camera、mediaType为Movie的视频,视频的最大长度为10秒。
11667

117-
Implement the **viewLibrary** method.
118-
11968
viewLibrary的实现 :
12069

121-
122-
```swift
70+
```
12371
@IBAction func viewLibrary(sender: AnyObject) {
12472
// Display Photo Library
12573
controller.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
@@ -130,13 +78,9 @@ viewLibrary的实现 :
13078
}
13179
```
13280

133-
The Photo library is displayed. If the mediaType isn't set to the movie
134-
type, the video files will not be displayed. Next, the delegate methods
135-
of the UIImagePickerControllerDelegate protocol needs to be implemented.
136-
13781
在调用上述代码之后,Photo library就会被显示。如果mediaType没有设置为Movie类型,视频文件就不会被显示出来。下一步就是实现UIImagePickerControllerDelegate协议的方法 :
13882

139-
```swift
83+
```
14084
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject: AnyObject]) {
14185
// 1
14286
let mediaType:AnyObject? = info[UIImagePickerControllerMediaType]
@@ -166,46 +110,23 @@ func imagePickerController(picker: UIImagePickerController, didFinishPickingMedi
166110
}
167111
```
168112

169-
The **imagePickerController(\_:didFinishPickingMediaWithInfo:)** method
170-
tells the delegate the user picked a movie. The info parameter contains
171-
the URL of the picked movie.
172-
173113
当用户选择了一个视频时`imagePickerController(\_:didFinishPickingMediaWithInfo:)`函数会被调用,info参数中会包含被选择的视频URL。
174114

175-
1. The mediatype from the info dictionary is checked if it is a movie
176-
type. If this is the case the URL of the video is extracted.
177-
2. The writeVideoAtPathToSavedPhotosAlbum method saves the video into
178-
the photo album
179-
3. The ViewController is dismissed
180-
181-
182115
1. 首先会检测info dictionary中的mediatype是否是movie类型,如果是那么则会提取这个视频的URL;
183116
2. 调用writeVideoAtPathToSavedPhotosAlbum函数将视频存储到图片相册中;
184117
3. 隐藏该ViewController。
185118

186-
Implement the **imagePickerControllerDidCancel** method
187-
188119
`imagePickerControllerDidCancel`实现如下 :
189120

190-
```swift
121+
```
191122
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
192123
picker.dismissViewControllerAnimated(true, completion: nil)
193124
}
194125
```
195126

196-
When the user press the Cancel button, the View Controller is dismissed.
197-
Build and Run the project on a real device, since the Simulator doesn't
198-
have a camera. Choose "Take Video" to shoot the video and click Use
199-
Video. Next, choose "View Library" and the video appears in the library.
200-
201127
当用户按下取消按钮,该界面的View Controller就会被隐藏。因为模拟器没有摄像头,因此编译并且将该项目运行到真实的设备,点击"Take Video"按钮来拍一段视频,然后点击“Use Video”。再下一步选择“View Library”,此时该Video就会显示在Library中了。
202128

203129
![TakeVideo-Device.png](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/559d107ee4b0a65ec39328be/1436356736349/TakeVideo-Device.png)
204130

205-
206-
You can download the source code of
207-
the **IOS8SwiftTakeVideoPlayerTutorial** at the ioscreator repository
208-
on [Github](https://github.com/ioscreator/ioscreator).
209-
210131
你可以在[这里](https://github.com/ioscreator/ioscreator)下载IOS8SwiftTakeVideoPlayerTutorial项目的完整代码。
211132

0 commit comments

Comments
 (0)