ios 自定义拍照页面_自定义UIImagePickerController的拍照页面(二)

本文介绍了如何自定义UIImagePickerController的拍照界面。通过查找并编辑视图,实现了添加自定义元素,如触摸视图、计时器按钮、连续拍摄按钮,并调整底部栏样式,包括重拍、保存按钮的文字以及相机按钮的行为。
摘要由CSDN通过智能技术生成

以前,写过一篇:自定义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];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值