永发信息网

如何自定义uiimagepickercontroller

答案:1  悬赏:70  手机版
解决时间 2021-11-28 07:00
如何自定义uiimagepickercontroller
最佳答案
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
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
IBM600拆后重装开机显示00161、00163
八字缺火怎么办,八字缺火对人的命运有哪些影
你好鸭名气为什么没有周黑鸭、绝味鸭脖的大?
我右眼有25度散光,后面写X175什么意思?配眼
农村173平方三层楼怎样设计
求AMD显卡的性能排行榜。
木器白漆可以喷墙吗
麻见隆一是什么眼型?
月满一轮辉宇宙,梅香千里到门庭,月下赏花当敬
古诗《忆母》倪瑞?是什么朝代人
某化学活动小组的同学,在实验室设计了两种除
家中正15烧香灵牌被烧是何征兆
我用UC浏览器收藏了一个网站但我把UC卸了再安
梦幻西游如何从三年内区转到三年外区?
我想投资金钥匙agk 可不会,想问问该怎么弄
推荐资讯
两袋糖果,第一袋的质量是第二袋的5倍多2.4千
ASTM A21相当于中国什么材质
人人财富商可靠吗
人心看透了,感觉真的很累,没有爱了
英雄杀的商店有没有三星朱元璋和三星虞姬,三
今天活虾什么价
83年5月9日金牛上升星座是什么
如何调查植物名称?自己采的标本不知道名字
皮草 水洗后 缩水了 怎么办 ?
汽车凸轮轴上置时驱动什么?
单选题下列不属于衡量区域发展水平的常用指标
估算题98.7+89约等于多少
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?