Reputation: 313
I need to add UIImagePickerController in camera mode using addSubView. I have written code for it but it leaves white space at the top of the view.
-(void)viewDidAppear:(BOOL)animated{
NSLog(@"ViewDidAppear");
OverlayView *overlay = [[OverlayView alloc]
initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,SCREEN_HEIGTH)];
//create a new image picker instance
picker = [[UIImagePickerController alloc]init];
self.picker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
//set source to video!
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//hide all controls
picker.showsCameraControls = NO;
picker.navigationBarHidden = NO;
picker.toolbarHidden = YES;
picker.editing = NO;
//make the video preview full size
picker.wantsFullScreenLayout = YES;
slider.value = 1;
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform,slider.value, slider.value);
//set our custom overlay view
picker.cameraOverlayView = overlay;
[picker.view addSubview:slider];
//show picker
[picker.view addSubview:capture];
[picker.view addSubview:library];
//[picker.view addSubview:multicapture];
[capture addTarget:self action:@selector(takepicture) forControlEvents:UIControlEventTouchUpInside];
[library addTarget:self action:@selector(goToLibrary) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:picker.view];
[picker viewWillAppear:YES];
[picker viewDidAppear:YES];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Test Text" message:@"Camera is Not Availble" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
[overlay release];
}
Can anyone please help me.
Thanks.
Upvotes: 2
Views: 3435
Reputation: 1001
As kante0 says, that white margin is the status bar disappeared. If you want to show the status bar, use kante0's solution:
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[self.view addSubview:picker.view];
If you don't want to show the status bar (typically when you show the camera preview), use this piece of code:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[self.view setFrame: [[UIScreen mainScreen] bounds]];
// Place your overlay view here
[self.view addSubview:picker.view];
But you have to remember that when the pickerview is removed, if you want to show again the status bar, you'll need to do this:
[picker.view removeFromSuperview];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
[self.view setFrame: [[UIScreen mainScreen] applicationFrame]];
// If you need to place elements programmatically, do it here
Upvotes: 2
Reputation: 2154
Is not a white margin, is status bar disappearing.
I solved the problem with:
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
Upvotes: 1
Reputation: 1889
Look into NSScreen
for getting accurate dimensions. Double check that you have the height value correct. For example, you could do this:
int width = [[NSScreen mainScreen] frame].size.width;
int height = [[NSScreen mainScreen] frame].size.height;
Upvotes: 1