【问题标题】:UIImagePickerController going to a white screen after the takePicture method is called调用 takePicture 方法后 UIImagePickerController 进入白屏
【发布时间】:2014-05-11 01:47:19
【问题描述】:

我正在尝试使用自定义 cameraOverlayViewUIImagePickerController 进行编程。当我调用UIImagePickerControllertakePicture 方法时,UIView 变为白屏,而不是您可以选择“使用照片”的选择器。如何将后续的UIView 设置为选择器而不是空白的UIView

我在下面包含了我的代码:

- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(applicationDidBecomeActive)
                                             name:UIApplicationDidBecomeActiveNotification
                                           object:nil];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self
                                                name:UIApplicationDidBecomeActiveNotification
                                              object:nil];
}

- (void)applicationDidBecomeActive
{




//Start the camera up

_imageViewPickerController = [[UIImagePickerController alloc] init];

//Hide default UI elements

_imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
_imageViewPickerController.showsCameraControls = NO;
_imageViewPickerController.navigationBarHidden = YES;
_imageViewPickerController.toolbarHidden = YES;

//Start the button overlay

UIView *btnView = [[UIView alloc] initWithFrame:_imageViewPickerController.view.bounds];
btnView.opaque = NO;
btnView.clipsToBounds = YES;

//Start up the button
UIButton *snapButton = [[UIButton alloc] initWithFrame:CGRectMake(-6, 504, 65, 65)];
snapButton.alpha = 0.5;
snapButton.transform = CGAffineTransformMakeRotation(DEGREES_RADIANS(90));
[snapButton addTarget:self action:@selector(snapThat) forControlEvents:UIControlEventTouchUpInside];

//Set the button's picture
UIImage *snapButtonImage = [UIImage imageNamed:@"Button.png"];
[snapButton setImage:snapButtonImage forState:UIControlStateNormal];

//Add button to the overlay
[btnView addSubview:snapButton];

//Overlay button view

_imageViewPickerController.cameraOverlayView = btnView;

//Fix for iPhone 5 and make fullscreen

CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -55.0);
CGAffineTransform scale = CGAffineTransformMakeScale(1.333333, 1.333333);
CGAffineTransform rotate = CGAffineTransformMakeRotation(DEGREES_RADIANS(180));
CGAffineTransform transform = CGAffineTransformConcat(translate, scale);
transform = CGAffineTransformConcat(transform, rotate);
_imageViewPickerController.cameraViewTransform = transform;

//Let's present it all

[self presentViewController:_imageViewPickerController
                   animated:NO
                 completion:NULL];


}

- (void)snapThat {
[_imageViewPickerController takePicture];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Save photo
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);
}
[picker dismissViewControllerAnimated:YES completion:NULL];
}

编辑:我已经修改了我的代码以包含它,但我仍然得到空白的 UIView: [self presentViewController:_imageViewPickerController animated:NO completion:NULL]; 这不应该保存图片并让我返回相机视图吗?

【问题讨论】:

    标签: ios objective-c cocoa-touch uiimagepickercontroller


    【解决方案1】:

    当我调用 UIImagePickerController 的 takePicture 方法时,UIView 变为白屏,而不是您可以选择“使用照片”的选择器。

    这样做是因为 在您的 didFinishPickingMediaWithInfo: 实现中调用了 dismissViewControllerAnimated:。如果您不想关闭相机界面,请不要关闭它。

    您不会获得任何自动第二视图(您可以在其中选择“使用照片”或其他)。如果需要,您必须创建自己的第二个视图控制器并将其推送到 UIImagePickerController(这是一个导航控制器)。

    【讨论】:

    猜你喜欢
    • 2011-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-11
    • 1970-01-01
    • 2017-06-15
    • 1970-01-01
    相关资源
    最近更新 更多