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

标签 iphone uiimagepickercontroller

我需要使用 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/

相关文章:

iphone - 拍照后翻转图像

swift - 如何将相机或图库拍摄的图像添加到按钮?

iphone - 从相机拍照并在 UIImageView 中显示

swift - ALAsset 已弃用 - 使用 Photos Framework 中的 PHAsset

uiimagepickercontroller - 如何判断从 didFinishPickingMediaWithInfo 返回的图像是来自相机还是相册?

ios - UIImagepicker 显示图像捕获而不是视频录制

ios - 如何在 TableView Cell 上使用 iOSCharts (https ://github. com/danielgindi/Charts)?

iphone - 将注释的标题设置为当前地址

iphone - 无法从 iPhone 连接基于 soap 的 wcf 服务

iphone - 使用 mac 的 google 工具箱编译单元测试时出错