我过去常常使用老式的方法在相机屏幕上添加叠加层,而且效果很好。但是,自3.1发布以来,Apple坚持要求我使用API添加叠加层。我很快就让叠加层工作,但似乎如果我使用自定义叠加层,那么移动&调整屏幕没有响应,我只能使用或重拍,实际上不能调整大小和移动。我正在使用的代码如下。我尝试了几种变体,但实际上只有这一点才能实现移动和放大。调整大小是删除添加自定义叠加层视图的行。
有什么想法吗?
UIImage *image = [UIImage imageNamed:@"camera-template-long.png"];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] ;
imgView.image = image;
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
overlayView.opaque = NO;
[overlayView addSubview:imgView];
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = YES;
picker.cameraOverlayView = overlayView;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentModalViewController:picker animated:YES];
答案 0 :(得分:3)
将allowsEditing
/ showsCameraControls
属性设置为NO,将原始视图准备为cameraOverlayView
,然后使用takePicture
方法。
然后,imagePickerController:didFinishPickingMediaWithInfo:
将被直接调用。
请尝试以下代码:
- (void)foo {
UIImagePickerController *controller = [[[UIImagePickerController alloc] init] autorelease];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
controller.cameraOverlayView = self.cameraOverlay;
[self performSelector:@selector(moveOverlayViewToSublayer:) withObject:controller afterDelay:0.1f];
controller.delegate = self;
[self presentModalViewController:controller animated:YES];
}
- (void) moveOverlayViewToSublayer:(UIImagePickerController*)controller {
CALayer *aLayer = self.cameraOverlay.layer.superlayer;
controller.cameraOverlayView = nil;
[aLayer addSublayer:self.cameraOverlay.layer];
}
我希望它能很好地运作。
答案 1 :(得分:3)
使用[overlayView setUserInteractionEnabled:NO];
停止叠加视图处理输入后,整个问题就消失了。
答案 2 :(得分:0)
http://www.techques.com/question/1-10178214/cameraOverlayView-prevents-editing-with-allowsEditing
这对我来说很有效。我试图禁用userInteractionEnabled但是徒劳无功。