1:让 UIImagePickerController 显示后 的状态栏始终保持某一种风格.
- -(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
- }
- -(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
- }
2:修改 UIImagePickerController 顶部导航栏的颜色风格
- [[imagePickerController navigationBar] setTintColor:[UIColor colorWithRed:78.0/255.0 green:148.0/255.0 blue:201.0/255.0 alpha:1]];
此方式同时适用于:短信,邮件等系统界面
3:是否显示照相机标准的控件库
- imagePickerController.showsCameraControls = NO;
4:将图片保存至系统照片库
- UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
成功失败后的回调:
- - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
- {
- myImageView.image = image;
- NSLog(@"%@",error);
- }
5:将视频保存至系统照片库
- NSString* path = [[info objectForKey:UIImagePickerControllerMediaURL] path];
- // 保存视频
- UISaveVideoAtPathToSavedPhotosAlbum(path, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
成功失败后的回调:
- - (void)video: (NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
- {
- NSLog(@"%@",videoPath);
- NSLog(@"%@",error);
- }
- //首先判断设备是否支持拍照功能
- if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
- if (imagePickerController == nil) {
- imagePickerController=[[UIImagePickerController alloc] init];
- //只开启拍照
- imagePickerController.sourceType=UIImagePickerControllerSourceTypeCamera;
- //拍照 摄影 同时开启
- //imagePickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
- //只开启 摄影
- //imagePickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
- imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;//视频质量:最好的
- imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront; //默认启用前置摄像头
- imagePickerController.delegate = self;
- imagePickerController.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
- imagePickerController.showsCameraControls = YES;//是否显示照相机标准的控件库
- [imagePickerController setAllowsEditing:NO];//是否加入照相后预览时的编辑功能
- //为相机添加自定义拍摄时的视图
- //imagePickerController.cameraOverlayView = imagePreviewViewController.view;
- CGRect rect = [[UIScreen mainScreen] bounds];
- rect.origin.y = rect.origin.y +50;
- rect.size.height = rect.size.height -130;
- UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
- [btn setFrame:rect];
- //[btn setTitle:@"试试" forState:UIButtonTypeRoundedRect];
- [btn addTarget:self action:@selector(SaveCamera) forControlEvents:UIControlEventTouchUpInside];
- [imagePickerController.view addSubview:btn];
- }
- [self presentModalViewController:imagePickerController animated:YES];
- }