gpt4 book ai didi

iphone - UIImagePickerController 使用 addSubView 在 View 顶部留下白边

转载 作者:行者123 更新时间:2023-12-03 20:45:50 25 4
gpt4 key购买 nike

我需要使用 addSubView 在相机模式下添加 UIImagePickerController。我已经为它编写了代码,但它在 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];

}

谁能帮帮我。

谢谢。

最佳答案

正如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];

但是你必须记住,当pickerview被删除时,如果你想再次显示状态栏,你需要这样做:

[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

关于iphone - UIImagePickerController 使用 addSubView 在 View 顶部留下白边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7028029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com