如何覆盖(添加UIImageView
这个)为相机预览和处理触摸?
我以前尝试做到这一点(如使用UIImagePickerController
并添加图像作为一个子视图)都失败了。
如何覆盖(添加UIImageView
这个)为相机预览和处理触摸?
我以前尝试做到这一点(如使用UIImagePickerController
并添加图像作为一个子视图)都失败了。
本教程介绍它: http://www.musicalgeometry.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