iPhone : 카메라 미리보기 오버레이
-
05-07-2019 - |
문제
오버레이를 추가하려면 어떻게합니까 (UIImageView
) 카메라 미리보기에 이것에 대한 손잡이가 있습니까?
이전 에이 작업을 시도했습니다 (예 : 사용 UIImagePickerController
그리고 이미지를 하위 뷰로 추가) 실패했습니다.
해결책
이 튜토리얼은 다음을 설명합니다. http://www.musicalgeometretic.com/?p=821
자습서에 표시된 빨간색 영역 대신 오버레이보기에 UIIMAGE를 추가하십시오.
다른 팁
구현 파일의 경우 :
- (IBAction)TakePicture:(id)sender {
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker.delegate = self;
OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
// Insert the overlay:
imagePicker.cameraOverlayView = overlay;
// Allow editing of image ?
imagePicker.allowsImageEditing = YES;
[imagePicker setCameraDevice:
UIImagePickerControllerCameraDeviceFront];
[imagePicker setAllowsEditing:YES];
imagePicker.showsCameraControls=YES;
imagePicker.navigationBarHidden=YES;
imagePicker.toolbarHidden=YES;
imagePicker.wantsFullScreenLayout=YES;
self.library = [[ALAssetsLibrary alloc] init];
// Show image picker
[self presentModalViewController:imagePicker animated:YES];
}
uiview 클래스를 만들고이 코드를 추가하십시오
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
// Clear the background of the overlay:
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
// Load the image to show in the overlay:
UIImage *overlayGraphic = [UIImage imageNamed:@"overlaygraphic.png"];
UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
overlayGraphicView.frame = CGRectMake(30, 100, 260, 200);
[self addSubview:overlayGraphicView];
}
return self;
}
추가 할 수 있습니다 UIImageView
대신 메인 창의 하위 뷰로 UIImagePicker
, 더 잘 작동 할 수 있습니다. 올바른 순서로 추가하거나 전화하십시오.
[window bringSubviewToFront:imageView];
카메라가 올라간 후.
당신이 터치를 처리하고 싶다면 UIImageView
당신은 그냥 추가 할 수 있습니다 UIImageView
일반적인 전체 화면의 하위 뷰로 View
투명한 배경으로 추가하십시오 저것 대신 창문으로, 정상 UIViewController
터치 이벤트를 처리하는 데 사용할 수있는 서브 클래스.
카메라 오버레이보기 (3.1 이상으로 제공됨)를 참조하십시오.
@property(nonatomic, retain) UIView *cameraOverlayView
제휴하지 않습니다 StackOverflow