以前,写过一篇:自定义UIImagePickerController的拍照页面,这篇文章的实现方式与此不同,在开始之前,先来看一下下面这张图:
上图对接下来的代码理解会很有帮助,红色的高亮部分是从屏幕上看到的照片的预览图,除了这个之外,他上面的view都可以去掉。
要想编辑这些View,需要先找到他们,这里给出了这个方法:
- (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];
}