每当我在设备上运行我的应用程序而我选择拍照时它会在没有警告的情况下崩溃,有人可以告诉我我的叠加层有什么问题吗?
除了使UIView成为超类之外,CameraOverlay.h不包含任何内容。
CameraOverlay.m
@implementation CameraOverlay
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
// load an image to show in the overlay
UIImage *constraints = [UIImage imageNamed:@"camera_overlay"];
UIImageView *constraintView = [[UIImageView alloc]initWithImage:constraints];
constraintView.frame = CGRectMake(30, 100, 260, 200);
[self addSubview:constraintView];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
viewController.m
- (IBAction)scanButton:(UIButton *)sender
{
CGRect screenRect = [[UIScreen mainScreen]bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CameraOverlay *overlay = [[CameraOverlay alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.cameraOverlayView = overlay;
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
答案 0 :(得分:1)
我发现了什么问题,我在将信号源设置到相机之前设置了相机的叠加层。
更新了ViewController
- (IBAction)scanButton:(UIButton *)sender
{
CGRect screenRect = [[UIScreen mainScreen]bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CameraOverlay *overlay = [[CameraOverlay alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraOverlayView = overlay;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentViewController:picker animated:YES completion:NULL];
}