重定义 UIImagePickerController
2011-11-04 13:57
190 查看
今天想实现一个类似Path 的Photo Picker的效果,没有Cancel按钮,取而代之的是添加一个从相册获取的按钮,要知道这在官方的SDK里面是没有。
开始之前,先做下功课,找到几个相关的文章
http://blog.airsource.co.uk/index.php/2008/11/11/views-of-uiimagepickercontroller/
http://www.cocoachina.com/bbs/read.php?tid-11664-page-1.html>
以下的这个框架图对接下来的工作会很有帮助
红色的高亮部分是从屏幕上看到的照片的预览图,除了这个之外,他上面的view都可以去掉。
要想编辑这些个View,得先找到他们,这里给出了个方法
#pragma mark get/show the UIView we want
//Find the view we want in camera structure.
-(UIView *)findView:(UIView *)aView withName:(NSString *)name{
Class cl = [aView class];
NSString *desc = [cl description];
if ([name isEqualToString:desc])
return aView;
for (NSUInteger i = 0; i < [aView.subviews count]; i++)
{
UIView *subView = [aView.subviews objectAtIndex:i];
subView = [self findView:subView withName:name];
if (subView)
return subView;
}
return nil;
}
怎么用,下面这段代码里给出了比较详细的例子
-(void)addSomeElements:(UIViewController *)viewController{
//Add the motion view here, PLCameraView and picker.view are both OK
UIView *PLCameraView=[self findView:viewController.view withName:@"PLCameraView"];
[PLCameraView addSubview:touchView];//[viewController.view addSubview:self.touchView];//You can also try this one.
//Add button for Timer capture
[PLCameraView addSubview:timerButton];
[PLCameraView addSubview:continuousButton];
[PLCameraView insertSubview:bottomBarImageView atIndex:1];
//Used to hide the transiton, last added view will be the topest layer
[PLCameraView addSubview:myTransitionView];
//Add label to cropOverlay
UIView *cropOverlay=[self findView:PLCameraView withName:@"PLCropOverlay"];
[cropOverlay addSubview:lblWatermark];
//Get Bottom Bar
UIView *bottomBar=[self findView:PLCameraView withName:@"PLCropOverlayBottomBar"];
//Get ImageView For Save
UIImageView *bottomBarImageForSave = [bottomBar.subviews objectAtIndex:0];
//Get Button 0
UIButton *retakeButton=[bottomBarImageForSave.subviews objectAtIndex:0];
[retakeButton setTitle:@"重拍" forState:UIControlStateNormal];
//Get Button 1
UIButton *useButton=[bottomBarImageForSave.subviews objectAtIndex:1];
[useButton setTitle:@"保存" forState:UIControlStateNormal];
//Get ImageView For Camera
UIImageView *bottomBarImageForCamera = [bottomBar.subviews objectAtIndex:1];
//Set Bottom Bar Image
UIImage *image=[[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"BottomBar.png"]];
bottomBarImageForCamera.image=image;
[image release];
//Get Button 0(The Capture Button)
UIButton *cameraButton=[bottomBarImageForCamera.subviews objectAtIndex:0];
[cameraButton addTarget:self action:@selector(hideTouchView) forControlEvents:UIControlEventTouchUpInside];
//Get Button 1
UIButton *cancelButton=[bottomBarImageForCamera.subviews objectAtIndex:1];
[cancelButton setTitle:@"取消" forState:UIControlStateNormal];
[cancelButton addTarget:self action:@selector(hideTouchView) forControlEvents:UIControlEventTouchUpInside];
}
开始之前,先做下功课,找到几个相关的文章
http://blog.airsource.co.uk/index.php/2008/11/11/views-of-uiimagepickercontroller/
http://www.cocoachina.com/bbs/read.php?tid-11664-page-1.html>
以下的这个框架图对接下来的工作会很有帮助
红色的高亮部分是从屏幕上看到的照片的预览图,除了这个之外,他上面的view都可以去掉。
要想编辑这些个View,得先找到他们,这里给出了个方法
#pragma mark get/show the UIView we want
//Find the view we want in camera structure.
-(UIView *)findView:(UIView *)aView withName:(NSString *)name{
Class cl = [aView class];
NSString *desc = [cl description];
if ([name isEqualToString:desc])
return aView;
for (NSUInteger i = 0; i < [aView.subviews count]; i++)
{
UIView *subView = [aView.subviews objectAtIndex:i];
subView = [self findView:subView withName:name];
if (subView)
return subView;
}
return nil;
}
怎么用,下面这段代码里给出了比较详细的例子
-(void)addSomeElements:(UIViewController *)viewController{
//Add the motion view here, PLCameraView and picker.view are both OK
UIView *PLCameraView=[self findView:viewController.view withName:@"PLCameraView"];
[PLCameraView addSubview:touchView];//[viewController.view addSubview:self.touchView];//You can also try this one.
//Add button for Timer capture
[PLCameraView addSubview:timerButton];
[PLCameraView addSubview:continuousButton];
[PLCameraView insertSubview:bottomBarImageView atIndex:1];
//Used to hide the transiton, last added view will be the topest layer
[PLCameraView addSubview:myTransitionView];
//Add label to cropOverlay
UIView *cropOverlay=[self findView:PLCameraView withName:@"PLCropOverlay"];
[cropOverlay addSubview:lblWatermark];
//Get Bottom Bar
UIView *bottomBar=[self findView:PLCameraView withName:@"PLCropOverlayBottomBar"];
//Get ImageView For Save
UIImageView *bottomBarImageForSave = [bottomBar.subviews objectAtIndex:0];
//Get Button 0
UIButton *retakeButton=[bottomBarImageForSave.subviews objectAtIndex:0];
[retakeButton setTitle:@"重拍" forState:UIControlStateNormal];
//Get Button 1
UIButton *useButton=[bottomBarImageForSave.subviews objectAtIndex:1];
[useButton setTitle:@"保存" forState:UIControlStateNormal];
//Get ImageView For Camera
UIImageView *bottomBarImageForCamera = [bottomBar.subviews objectAtIndex:1];
//Set Bottom Bar Image
UIImage *image=[[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"BottomBar.png"]];
bottomBarImageForCamera.image=image;
[image release];
//Get Button 0(The Capture Button)
UIButton *cameraButton=[bottomBarImageForCamera.subviews objectAtIndex:0];
[cameraButton addTarget:self action:@selector(hideTouchView) forControlEvents:UIControlEventTouchUpInside];
//Get Button 1
UIButton *cancelButton=[bottomBarImageForCamera.subviews objectAtIndex:1];
[cancelButton setTitle:@"取消" forState:UIControlStateNormal];
[cancelButton addTarget:self action:@selector(hideTouchView) forControlEvents:UIControlEventTouchUpInside];
}
相关文章推荐
- UIImagePickerController拍照与摄像
- UIImagePickerController使用
- UIImagePickerController的一些属性(调照相机或者图片)
- UIImagePickerController拍照与摄像
- UIImagePickerController
- iOS之UIImagePickerController的应用
- UIImagePickerController, UISearchBar
- 使用UIImagePickerController从IPhone照片库或照相机获取图像
- 不使用UIImagePickerController实现读取相册图片的方法
- UIImagePickerController
- UIImagePickerController 的基本用法 - iOS - UI基础知识总结14
- 高级UIKit-06(UIImagePickerController)
- One-tap UIImagePickerController (iPhone camera)
- UIImagePickerController 图像选取器--在iPhone中调用照相机、照片库—IOS开发
- UIImagePickerController拍照与摄像
- 重定义 UIImagePickerController
- UIImagePickerController的静态方法
- iOS8下,UIImagePickerController的popoverPresentationController为空,要怎么获取?
- iphone UIImagePickerController组件图片旋转问题
- IOS UIImagePickerViewController相关(转)