UIImagePickerController簡單使用

來源:互聯網
上載者:User

標籤:

UIImagePickerController簡單使用

UIImagePickerController用於管理可自訂的,系統支援的用於擷取裝置片和視頻的使用者介面。同時可以用於在App中選擇儲存的圖片和視頻。一個UIImagePickerController系統管理使用者互動並且將這些互動結果傳遞給一個代理對象。該類不能被繼承和修改,除了自訂cameraOverlayView外。


UIVideoEditorController

Media Capture and Access to Camera;


先簡單講解下UIImagePickerController的一些屬性,在上代碼。

一常用屬性

(1)sourceType 控制器展示的選擇介面的類型,

包含三個枚舉值

enum {   UIImagePickerControllerSourceTypePhotoLibrary,      //在圖片庫中選取圖片或者視頻   UIImagePickerControllerSourceTypeCamera,            //用於拍攝照片或視頻   UIImagePickerControllerSourceTypeSavedPhotosAlbum   //在相簿中選取圖片或視頻};typedef NSUInteger UIImagePickerControllerSourceType;

(2)mediaTypes

預設值是kUTTypeImage,意味著使用者只能選擇靜態圖片或者拍攝靜態圖片(相對於視頻)

當mediaTypes設定為kUTTypeImage,kUTTypeMovie(裝置支援的話)時,操作圖片的同時,可以選擇操作視頻。

使用KUTTypeImage,KUTTypeMovie時,需匯入#import <MobileCoreServices/MobileCoreServices.h>

(3)allowEditing

使用者是否可以修改圖片或視頻,預設是NO

(3)cameraOverlayView

The view to display on top of the default image picker interface.


二基本用法

(1)使用isSourceTypeAvailable:來判斷當前裝置是否支援該SourceType 

(2)若支援,使用availableMediaTypesForSourceType來檢驗當前SourceType下支援的mediaTypes

(3)若需要調整mediaTypes(預設是kUTTypeImage),調整

(4)展示介面,使用modal方式彈出。

(5)當使用者操作完成(cancel或者選著了某張圖片和某個視頻),代理會觸發方法,然後關閉介面並進行相關的處理。


三詳解

其他兩種sourceType使用方式較為單一,下面詳細講解下當SourceType為UIImagePickerControllerSourceTypeCamera時的情況。

常見屬性

(1)videoQuality:用於設定視頻的品質,預設值為UIImagePickerControllerQualityTypeMedium.

用於拍攝視頻和選著視頻,如果選擇已經存在的視頻,且該視頻的品質高於設定的videoQuality,則視頻會被轉為低品質的

(如果存在的視頻地獄videoQuality呢)

(2)videoMaximumDuration 最大的視頻時間,預設為10分鐘


(3)cameraViewTransform

?這幾個屬性只在camera下可用


(4)cameraDevice

enum {   UIImagePickerControllerCameraDeviceRear,  //後置網路攝影機   UIImagePickerControllerCameraDeviceFront  //自拍};typedef NSUInteger UIImagePickerControllerCameraDevice;

 (5)cameraCaptureMode

開啟照相介面的時候選擇的模式

enum {   UIImagePickerControllerCameraCaptureModePhoto,  //預設使用拍照模式   UIImagePickerControllerCameraCaptureModeVideo   //預設使用攝像模式};typedef NSUInteger UIImagePickerControllerCameraCaptureMode;

(6)cameraFlashMode 

閃光燈

enum {   UIImagePickerControllerCameraFlashModeOff  = -1,   UIImagePickerControllerCameraFlashModeAuto = 0,   UIImagePickerControllerCameraFlashModeOn   = 1};typedef NSInteger UIImagePickerControllerCameraFlashMode;

The value of this property specifies the behavior of the still-image flash when the value of the cameraCaptureMode property is UIImagePickerControllerCameraCaptureModePhoto, and specifies the behavior of the video torch when cameraCaptureMode is UIImagePickerControllerCameraCaptureModeVideo.


自訂cameraOverlayView以及相關方法

明天再說



available

UIImagePickerController簡單使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.