gpt4 book ai didi

iphone - 使用自定义相机覆盖 iPhone SDK 3.1+ 时,图像移动和调整大小不起作用

转载 作者:行者123 更新时间:2023-12-03 19:38:13 26 4
gpt4 key购买 nike

我曾经使用老式方法在相机屏幕上添加覆盖层,效果很好。然而,自从 3.1 出来之后,Apple 就坚持让我使用 API 添加覆盖层。我很快就让叠加层开始工作,但似乎如果我使用自定义叠加层,则移动和调整大小屏幕没有响应,我只能使用或重新拍摄,实际上无法调整大小和移动。我正在使用的代码如下。我尝试了几种变体,但真正启用移动和调整大小的唯一方法是删除添加自定义覆盖 View 的行。

有什么想法吗?

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];

最佳答案

allowsEditing/showsCameraControls 属性设置为 NO,将原始 View 准备为 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];
}

希望它能运作良好。

关于iphone - 使用自定义相机覆盖 iPhone SDK 3.1+ 时,图像移动和调整大小不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1990573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com