Reputation:
Whenever I run my app on a device and I choose to take a picture it crashes without warning can someone tell me what is wrong with my overlay?
CameraOverlay.h does not contain anything besides making UIView the superclass.
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];
}
Upvotes: 0
Views: 1254
Reputation:
I found out what was wrong, I was setting the overlay of the camera before I set the source to the camera.
Updated code from the 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];
}
Upvotes: 1