我有一个透明视图,使用CoreGraphics绘制一个矩形。 当相机启动时,自定义叠加视图位于快门动画上方。 你看到的是标准相机快门,上面有自定义矩形。 如何让它在快门动画下面的正确位置?我查看了其他示例代码,但它适用于OS 3.1,似乎没有做任何不同的事情。
这是我的代码:
-(IBAction)cameraButton{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerCameraDeviceRear]){
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Add the OverlayView with the custom Rectangle
CGRect overlayFrame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
OverlayView *overlayView = [[OverlayView alloc]initWithFrame:overlayFrame];
picker.cameraOverlayView = overlayView;
[overlayView release];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
答案 0 :(得分:2)
在iPad上,此问题不存在,默认情况下,叠加视图位于快门动画后面。但在iPhone上,叠加层出现在前面。
我找到了一个适合我的解决方案。
您必须在此方法中将叠加视图设置为子视图:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (!viewController)
return;
UIView* controllerViewHolder = viewController.view;
UIView* controllerCameraView = [[controllerViewHolder subviews] objectAtIndex:0];
UIView* controllerPreview = [[controllerCameraView subviews] objectAtIndex:0];
[controllerCameraView insertSubview:self.overlayView aboveSubview:controllerPreview];
}
希望有所帮助
原始来源: http://www.alexcurylo.com/blog/2009/06/18/uiimagepickercontroller-in-3-0/
答案 1 :(得分:1)
除了你已经在做的事情之外,你可能不会做任何其他事情;如果iOS决定将叠加视图放在快门上,您只需要使用它(除非您想冒着被应用商店拒绝的风险)。
作为一种不完美的解决方法,您可以使用alpha = 0启动叠加层,然后在一两秒后将alpha设置为1。但是在打开之前没有设置快门显示的时间段(我认为它取决于初始化相机硬件需要多长时间),所以有时你的界面可能不会出现,直到很晚,有时候可能显得太早。 / p>
答案 2 :(得分:0)
从4.3.3开始,快门动画被破坏,因为元素显示在顶部,然后在动画开始时在下面拍摄。我已将此作为雷达提交:http://openradar.appspot.com/radar?id=1204401
答案 3 :(得分:0)
我回答了类似的问题here。对我有用(在iOS 6中)是在navigationController中设置cameraOverlayView:willShowViewController:animated。
- (void) navigationController:(UINavigationController*) navigationController willShowViewController:(UIViewController*) viewController animated:(BOOL) animated {
self.imagePickerController.cameraOverlayView = ...; // your camera overlay view
}