UIImagePickerController 能自定义吗

 我来答
百度网友10a24bf
2017-07-08 · TA获得超过1.3万个赞
知道大有可为答主
回答量:1.3万
采纳率:95%
帮助的人:2794万
展开全部
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];
}
意法半导体(中国)投资有限公司
2023-06-12 广告
单片机,单片微型计算机。它是把中央处理器(CPU)、随机存取存储器(RAM)、只读存储器(ROM)、输入/输出端口(I/O)等主要计算机功能部件都集成在一块集成电路芯片上的微型计算机。单片机具有性能高、速度快、体积小、价格低、稳定可靠、应用... 点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式