我需要使用addSubView在相机模式下添加UIImagePickerController。我已经为它编写了代码,但它在视图的顶部留下了空白区域。
-(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];
}
任何人都可以帮助我。
感谢。
答案 0 :(得分:2)
正如kante0所说,白边是状态栏消失了。如果要显示状态栏,请使用kante0的解决方案:
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[self.view addSubview:picker.view];
如果您不想显示状态栏(通常在显示相机预览时),请使用以下代码:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[self.view setFrame: [[UIScreen mainScreen] bounds]];
// Place your overlay view here
[self.view addSubview:picker.view];
但是你必须记住,当删除选择器视图时,如果你想再次显示状态栏,你需要这样做:
[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
答案 1 :(得分:1)
了解NSScreen
获取准确的尺寸。仔细检查您的高度值是否正确。例如,您可以这样做:
int width = [[NSScreen mainScreen] frame].size.width;
int height = [[NSScreen mainScreen] frame].size.height;
答案 2 :(得分:1)
不是白色边缘,状态栏消失。
我用以下方法解决了问题:
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];