gpt4 book ai didi

ios - 拍照并尝试关闭 didFinishPickingMediaWIthInfo 中的预览

转载 作者:行者123 更新时间:2023-11-29 12:26:01 24 4
gpt4 key购买 nike

在我的应用程序上拍摄照片后,我试图关闭预览。我只想按下快门按钮,然后弹回显示 UIImagePickerControllerUIViewController,而不显示图像预览以及“重拍”和“使用照片”按钮。我正在使用这段代码:

- (IBAction)pushTakePhoto:(id)sender {

self.picker = [[UIImagePickerController alloc] init];
self.picker.delegate = self;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraDevice=UIImagePickerControllerCameraDeviceFront;



UIImage *catEars = [UIImage imageNamed:@"cameraoverlay"];//320*101
UIImageView *overlayImageView = [[UIImageView alloc] initWithImage:catEars];
CGRect screenRect = [[UIScreen mainScreen] bounds];
self.earsX = screenRect.size.width/2-overlayImageView.frame.size.width/2;
self.earsY = 120;
self.earsWidth = overlayImageView.frame.size.width;
self.earsHeight = overlayImageView.frame.size.height;

//bar size is 40 at the top and the bottom one is 101


overlayImageView.frame=CGRectMake(self.earsX, self.earsY, self.earsWidth, self.earsHeight);
[self.picker setCameraOverlayView:overlayImageView];

[self presentViewController:self.picker animated:YES completion:NULL];


}

并且在 didFinishPickingMediaWIthInfo 中,我正在尝试使用 [self.picker dismissViewControllerAnimated:YES completion:nil]; 但是它没有任何影响。谁能给我一些关于如何解决这个问题的建议?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

[self.picker dismissViewControllerAnimated:YES completion:nil];

}

最佳答案

在viewDidLoad中添加这段代码

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadPhotoCaptured) name:@"_UIImagePickerControllerUserDidCaptureItem" object:nil];

然后实现这个方法

尝试

- (void)loadPhotoCaptured
{
UIImage *img = [[[self allImageViewsSubViews:[[[picker viewControllers]firstObject] view]] lastObject] image];
if (img)
{
[self imagePickerController:nil didFinishPickingMediaWithInfo:[NSDictionary dictionaryWithObject:img forKey:UIImagePickerControllerOriginalImage]];
}
else
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
}

- (NSMutableArray*)allImageViewsSubViews:(UIView *)view
{
NSMutableArray *arrImageViews=[NSMutableArray array];
if ([view isKindOfClass:[UIImageView class]])
{
[arrImageViews addObject:view];
}
else
{
for (UIView *subview in [view subviews])
{
[arrImageViews addObjectsFromArray:[self allImageViewsSubViews:subview]];
}
}
return arrImageViews;
}

关于ios - 拍照并尝试关闭 didFinishPickingMediaWIthInfo 中的预览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29101463/

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