UIImagePickerController使用

最近在做照相,研究下UIImagePickerController的使用方法。引用UIImagePickerController  需用到两个代理<UIImagePickerControllerDelegate,UINavigationControllerDelegate>用UIImagePickerController选择、显示图片或视频,主要注意UIImagePickerController几个属性的设置



一:UI 显示样式,显示的格式确定
1:sourceType
@property(nonatomic) UIImagePickerControllerSourceType sourceType
enum {
UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
};
typedef NSUInteger UIImagePickerControllerSourceType;
sourceType用来确定用户界面显示的样式:
共三种格式
UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum

为了区分是否支持所需引用的sourceType,一般要用到下面这个函数,以便确定sourceType。

+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType



2:   mediaTypes
@property(nonatomic,copy) NSArray *mediaTypes
mediaTypes用来确定再picker里显示那些类型的多媒体文件,图片?视频?
+ (NSArray *)availableMediaTypesForSourceType:(UIImagePickerControllerSourceType)sourceType

UIImagePikerController的一些属性和方法:

 

@property(nonatomic)           UIImagePickerControllerSourceType     sourceType;                  

@property(nonatomic,copy)      NSArray                              *mediaTypes;                   //是否允许对获得的图片进行编辑,default value is NO.

@property(nonatomic)           BOOL                                  allowsEditing              //是否在确定页面出现裁剪框,进行裁剪

@property(nonatomic)           BOOL                                  allowsImageEditing    //目前已经被allowsEditing所替代

@property(nonatomic)           NSTimeInterval                        videoMaximumDuration   //视频最大的时间长度



//拍摄照片的清晰度,只有在照相机模式下可用

enum {

    UIImagePickerControllerQualityTypeHigh = 0,       // 高质量

    UIImagePickerControllerQualityType640x480 = 3,    // VGA quality

    UIImagePickerControllerQualityTypeMedium = 1,     // 中质量,适合于wifi传输

    UIImagePickerControllerQualityTypeLow = 2         // 低质量,适合于蜂窝数据传输

};

typedef NSUInteger UIImagePickerControllerQualityType;

 

@property(nonatomic)           UIImagePickerControllerQualityType    videoQuality    //默认选中的是UIImagePickerControllerQualityTypeMedium


@property(nonatomic)           BOOL                                  showsCameraControls    //是否显示照相机其他控件,默认yes


@property(nonatomic,retain)    UIView                                *cameraOverlayView    //类似相框

@property(nonatomic)           CGAffineTransform                     cameraViewTransform   //设定图像缩放, 如:picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, 1.0, 1.0); 




//可以设置照相机的模式,照相还是录视频,默认照相模式。

enum {

    UIImagePickerControllerCameraCaptureModePhoto,

    UIImagePickerControllerCameraCaptureModeVideo

};

typedef NSUInteger   UIImagePickerControllerCameraCaptureMode;

@property(nonatomic) UIImagePickerControllerCameraCaptureMode    cameraCaptureMode   


@property(nonatomic) UIImagePickerControllerCameraDevice      cameraDevice   //设置哪个引用摄像头,前置还是后置摄像头,默认是后置



//设置闪光灯模式

enum {

    UIImagePickerControllerCameraFlashModeOff  = -1,

    UIImagePickerControllerCameraFlashModeAuto = 0,

    UIImagePickerControllerCameraFlashModeOn   = 1

};

typedef NSInteger UIImagePickerControllerCameraFlashMode;   

@property(nonatomic) UIImagePickerControllerCameraFlashMode   cameraFlashMode  


@property(nonatomic) BOOL   showsCameraControls    //设置是否隐藏所有的标准的UI界面,默认是YES,(代表是用标准的UI界面)


@property(nonatomic,retain) UIView     *cameraOverlayView   //添加自定义信息层



IOS拍照控件同时显示拍照与录像

- (void) recordVideo: (id) sender
{

UIImagePickerController *ipc = [[UIImagePickerController alloc] init];

ipc.sourceType =  UIImagePickerControllerSourceTypeCamera;

ipc.delegate = self;

ipc.allowsEditing = YES;

ipc.videoQuality = UIImagePickerControllerQualityTypeMedium;

ipc.videoMaximumDuration = 30.0f; // 30 seconds

///ipc.mediaTypes = [NSArray arrayWithObject:@"public.movie"];

//主要是下边的两能数,@"public.movie", @"public.image"  一个是录像,一个是拍照

ipc.mediaTypes = [NSArray arrayWithObjects:@"public.movie", @"public.image", nil];

[self presentModalViewController:ipc animated:YES];

}

你可能感兴趣的:(UIImagePickerController使用)