jjzjj

iphone - iOS 7 UIImagePickerController 相机覆盖静态图像

coder 2023-09-30 原文

iOS 7 使用 UIImagePickerController 拍照两次,第二次会显示覆盖相机的静态图像,如何重置相机。

我试着一张一张拍,一共拍了5张。

它适用于 iOS6。

在iOS7上,第一次可以正常使用,但是第二次拍照时,屏幕上会出现静态的暗图像,如何清除或重置,虽然拍照有效,但用户看不到相机会捕捉到什么。

bool fistTimeToShow = YES;

-(void) viewDidAppear:(BOOL)animated{
    if (fistTimeToShow) {
        fistTimeToShow = NO;

        self.imagePickerController = nil;

        [self tackImage];
    }
}

-(void)tackImage{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        self.imagePickerController = [[UIImagePickerController alloc]init];
        self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        self.imagePickerController.showsCameraControls = YES;
        self.imagePickerController.delegate = self;

        [self presentViewController:self.imagePickerController animated:NO completion:nil];
    }
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    NSLog(@"====== imagePickerController:didFinishPickingMediaWithInfo ======");
    [self.imagePickerController dismissViewControllerAnimated:NO completion:nil];

    //...deal with the image capture...

    self.imagePickerController = nil;

    [self tackImage];
}

更新

我更改了 dismiss 函数以将 [self tackImage]; 放入 block 中。现在它总是显示拍摄的拳头图像。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    NSLog(@"====== imagePicker: didFinish ======");

    self.imagePickerController = nil;

    [self dismissViewControllerAnimated:NO completion: ^{
        [self tackImage];
    }];
}

我正在尝试找到一种清除图像的方法。但我还不知道图像保存在哪里。

更新2

使用

[self performSelector:@selector(presentCameraView) withObject:nil afterDelay:1.0f];

和函数

-(void)presentCameraView{
    [self presentViewController:self.imagePickerController animated:NO completion:nil];
}

替换。 [self presentViewController:self.imagePickerController animated:NO completion:nil]; 它无论如何都可以在我的设备上运行,但我什至不知道为什么。

更新3

Delay:1.0f 时,我已将 userInteractionEnabled 设置为 NO 以避免其他问题,并且可能还需要设置 navigationBartabBar 具体使用。

最佳答案

我在 iOS 7 下使用 Xamarin.iOS 时遇到了完全相同的问题。

有帮助的是在 didFinishPickingMediaWithInfo 方法中添加 GC.Collect()。 在 C# 中,GC.Collect() 从未使用/处置的对象中“清理”内存。

当然,在 Obj-C 中没有直接的等价物,但这也可能对您的问题有所启发(它可能与内存相关)。

关于iphone - iOS 7 UIImagePickerController 相机覆盖静态图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18998190/

有关iphone - iOS 7 UIImagePickerController 相机覆盖静态图像的更多相关文章

随机推荐