如何自定义uiimagepickercontroller

如题所述

第1个回答  2015-12-31
  1.设定imagePacker参数
  // Transform values for full screen support:
  #define CAMERA_TRANSFORM_X 1
  // this works for iOS 4.x
  #define CAMERA_TRANSFORM_Y 1.24299

  -(void)viewWillAppear:(BOOL)animated{
  
  UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
  imagePickerController.delegate = self;

  imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
  imagePickerController.showsCameraControls = NO;
  imagePickerController.navigationBarHidden = YES;
  imagePickerController.wantsFullScreenLayout = YES;
  imagePickerController.cameraViewTransform =CGAffineTransformScale(imagePickerController.cameraViewTransform, CAMERA_TRANSFORM_X,CAMERA_TRANSFORM_Y);
  cameraViewController = [[CameraOverlayViewControlleralloc]initWithNibName:@"CameraOverlayViewController" bundle:nil];
  imagePickerController.cameraOverlayView = cameraViewController.view;
  cameraViewController.pickerController = imagePickerController;
  [self presentModalViewController:imagePickerController animated:NO];
  [imagePickerController release];
  }

  2.代理方法

  -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
  [picker dismissModalViewControllerAnimated:NO];
  UIImage* image = [info valueForKey:UIImagePickerControllerOriginalImage];
  BeautifyPhotoViewController* beautifyPhotoViewController = [[BeautifyPhotoViewControlleralloc]initWithNibName:@"BeautifyPhotoViewController" bundle:nil];
  beautifyPhotoViewController.photoImage = image;
  [self.navigationController pushViewController:beautifyPhotoViewController animated:YES];
  [beautifyPhotoViewController release];
  }

  3.overlayView对应的controller

  #import "CameraOverlayViewController.h"

  @interface CameraOverlayViewController ()

  @end

  @implementation CameraOverlayViewController

  @synthesize pickerController;
  @synthesize cameraScaleBtn;
  @synthesize titleImageView;
  @synthesize flashModeBtn;
  @synthesize deviceModeBtn;
  @synthesize photoBtn;

  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  if (self) {
  // Custom initialization
  [self getAllPhotoImages];
  }
  return self;
  }

  - (void)viewDidLoad
  {
  [super viewDidLoad];
  isOneToOne = YES;
  imageArray = [[NSMutableArray alloc]init];
  shadowView = [[ShadowView alloc]initWithRect:CGRectMake(0, 80, 320, 320)];
  [self.view addSubview:shadowView];
  [self.view sendSubviewToBack:shadowView];
  [shadowView release];
  // Do any additional setup after loading the view from its nib.
  }

  - (void)viewDidUnload
  {
  [super viewDidUnload];
  // Release any retained subviews of the main view.
  // e.g. self.myOutlet = nil;
  }
  //闪光灯
  -(IBAction)cameraTorchOn:(id)sender{
  if (pickerController.cameraFlashMode ==UIImagePickerControllerCameraFlashModeAuto) {
  pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
  }else {
  pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
  }
  }

  //前后摄像头
  - (IBAction)swapFrontAndBackCameras:(id)sender {
  if (pickerController.cameraDevice ==UIImagePickerControllerCameraDeviceRear ) {
  pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
  }else {
  pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
  }
  }
  //改变拍摄比例
  -(IBAction)changeCameraScale:(id)sender{
  if (isOneToOne) {
  [shadowView changeRect:CGRectMake(0, 0, 320, 428)];
  [cameraScaleBtn setImage:[UIImage imageNamed:@"font_-scale43.png"]forState:UIControlStateNormal];
  titleImageView.alpha = 0.2;
  flashModeBtn.alpha = 0.5;
  deviceModeBtn.alpha = 0.5;
  isOneToOne = NO;
  }else {
  [shadowView changeRect:CGRectMake(0, 80, 320, 320)];
  [cameraScaleBtn setImage:[UIImage imageNamed:@"font_-scale11.png"]forState:UIControlStateNormal];
  titleImageView.alpha = 1;
  flashModeBtn.alpha = 1;
  deviceModeBtn.alpha = 1;
  isOneToOne = YES;
  }
  }

  - (IBAction)enterPhotoAlbum:(id)sender {
  PhotoAlbumViewController* photoAlbumViewController = [[PhotoAlbumViewControlleralloc]initWithNibName:@"PhotoAlbumViewController" bundle:nil];
  [self presentModalViewController:photoAlbumViewController animated:YES];
  
  }

  //拍摄照片
  -(IBAction)takeThePic:(id)sender{
  [pickerController takePicture];
  }

  -(IBAction)backToHome:(id)sender{
  [pickerController dismissModalViewControllerAnimated:NO];
  [[NSNotificationCenter defaultCenter] postNotificationName:@"backToHome" object:nil];
  }

  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
  return (interfaceOrientation == UIInterfaceOrientationPortrait);
  }

  - (void)dealloc
  {
  [cameraScaleBtn release];
  [flashModeBtn release];
  [deviceModeBtn release];
  [titleImageView release];
  [super dealloc];
  }

  -(void)getAllPhotoImages{
  ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror){
  
  NSLog(@"error occour =%@", [myerror localizedDescription]);
  };
  ALAssetsGroupEnumerationResultsBlock groupEnumerAtion = ^(ALAsset *result, NSUInteger index,BOOL *stop){
  if (result!=NULL) {
  if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
  [imageArray addObject:result];
  UIImage *img=[UIImage imageWithCGImage:result.thumbnail];
  [photoBtn setImage:img forState:UIControlStateNormal];
  }
  }
  };
  ALAssetsLibraryGroupsEnumerationResultsBlock
  
  libraryGroupsEnumeration = ^(ALAssetsGroup* group, BOOL* stop){
  
  if (group == nil) {
  return;
  }
  if (group!=nil) {
  [group enumerateAssetsUsingBlock:groupEnumerAtion];
  }
  };
  ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
  
  [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
  
  usingBlock:libraryGroupsEnumeration
  
  failureBlock:failureblock];
  [library release];
  }
  @end本回答被提问者采纳

如何创建自定义的 UIImagePickerController 与全屏图像 ios
1. 初始化UIImagePickerController 类;2. 设置UIImagePickerController 实例的数据来源类型(下面解释);3. 设置设置代理;4. 如果需要做图片修改的话设置allowsEditing =yes。数据来源类型一共有三种:enum { UIImagePickerControllerSourceTypePhotoLibrary ,\/\/来自图库 UIImagePickerControllerSourceTypeCamera...

如何创建自定义的 UIImagePickerController 与全屏图像 ios
第一个项目符号点,我想你可以使用 cameraOverlayView 属性的 UIImagePickerController 要在选取器默认接口添加您的自定义 UI 对象:- (IBAction)pick:(id)sender { NSLog(@"abc");picker = [[UIImagePickerController alloc] init];if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerCont...

UIImagePickerController 能自定义吗
imagePickerController.cameraOverlayView = cameraViewController.view;cameraViewController.pickerController = imagePickerController;[self presentModalViewController:imagePickerController animated:NO];[imagePickerController release];} 2.代理方法 -(void)imagePickerController:(UIImagePickerController *)pick...

UIImagePickerController 能自定义吗
UIImagePickerController 能自定义 配置goclipse(可选)(如果不喜欢eclipse开发工具,请跳过这个配置。)1、下载并安装goclipse插件。Goclipse是go语言for eclipse的插件 2、启动eclipse并创建go项目。然后写个最简单的helloworld.go文件,并运行。代码如下:packagemainimport"fmt"func main(){ fmt.Printf...

UIImagePickerController的编辑模式怎么设置裁剪框的大小或形状_百度知 ...
编辑界面下,点击编辑选项面板上的“剪裁”,出现参数调节选项,同时照片上出现裁剪框: 可以通过改变裁剪框的位置和大小选择图片的裁剪区域。 裁剪结束后,点击“应用”按钮保留此次修改,或点击“取消”按钮忽略此次修改,点击后调节选项收起。

UIImagePickerController的编辑模式怎么设置裁剪框的大小或形状_百度知 ...
imagePickerController.allowsEditing = NO;\/\/不显示图片剪裁框;如果不显示图片,在获取图片的方法里获取设置成如下:image = [info objectForKey:UIImagePickerControllerOriginalImage];

UIImagePickerController只选择相片或者视频的实现
一般我们会用到选择相册和拍照功能,但是拍照功能是设置mediaType = UIImagePickerControllerSourceTypeCamera,而选择相册是mediaType = UIImagePickerControllerSourceTypePhotoLibrary(出现相册选项,可以选择进入不同的相册薄),选择所有相册内的图片和视频是用mediaType = UIImagePickerControllerSourceTypeSaved...

iOS使用UIImagePickerController拍照和视频录制
指定的源设备上可用的媒体类型,一般就是图片和视频 + (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType;指定来源是否支持:UIImagePickerControllerSourceTypePhotoLibrary:来自图库 UIImagePickerControllerSourceTypeCamera:来自相机 UIImagePickerControllerSourceTypeSavedPhotosAlbum:来自相册...

uiimagepickercontroller 怎么添加overlay
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;这个时候没有状态栏,经过测试(没找到文档),Edit状态的裁剪窗口是320*320的,Y是75所以我可以精确的把overlay匹配位置 如果是album获取的,是不可以在创建UIImagePicker的时候设置overlay的,因为cameraOverlayView顾名思义就是为摄像头准备的...

让UIImagePickerController支持多选
调查了一些开源的框架,发现都是使用 ALAssetsLibrary 库并且都是从头开始搭建UI,好处就是自定义强,坏处就是工作量大,容易出Bug,维护方面肯定没有Apple做的好。基于以上所依我打算在UIImagePickerController的基础上为其添加多选支持。主要思路就是上面这两点,最终的效果如下:源码请移步 Github ...

相似回答