gpt4 book ai didi

ios - 为什么禁用 allowsEditing 时,iPhone 上的相机拍摄的全屏照片不会显示在 UIImageview 中?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:09:53 24 4
gpt4 key购买 nike

在我的应用程序中,我从 iPhone 相机拍摄照片并将这些照片放入带有图像的 ScrollView 中。

问题是它只在我设置的情况下有效

picker.allowsEditing = YES

但在这种情况下,照片只会以正方形形式保存(感谢 allowsEditing,相机功能中有一个选择正方形)。

如果我删除这行代码(我想要的是因为我想要完整的照片,而不仅仅是它的一个选定的正方形),那么占位符图像将被替换为任何内容。

这里是需要的方法:

- (IBAction)takePhoto:(UIButton *)sender{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
//picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImageView *image = (UIImageView *)[self.view viewWithTag:[self getCurrentPageNumber]];
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
image.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];}

-(void)addImageToImageScrollView:(CGFloat)x y:(CGFloat)y width:(CGFloat)width height:(CGFloat)height {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)];
imgView.image = [UIImage imageNamed:@"placeholder.png"];
imgView.contentMode = UIViewContentModeScaleAspectFit;
[imgView setTag:([self getCurrentPageNumber]+1)];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(imageScrollViewButtonPressed:) forControlEvents:UIControlEventTouchDown];
button.frame = CGRectMake(0, 0, view.frame.size.width, view.frame.size.height);
[button setTag:([self getCurrentPageNumber]+1)];
[view addSubview:imgView];
[view addSubview:button];
[imageScrollView addSubview:view];}

最佳答案

它与 UIImagePickerControllerDelegate 协议(protocol)有关

当您设置 allowsEditing 时是,那么当委托(delegate)方法触发时,您将开始收到一个充满有用信息的 NSDictionary:

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

当您调用 UIImage *chosenImage = info[UIImagePickerControllerEditedImages]; 时,您正在使用其中的一些信息



<p>by setting <code>allowsEditing</code> to <code>NO</code> the delegate method will pass nil in for the <code>info</code> argument.</p>

You can confirm this by setting a breakpoint in your method, stepping in and observing that the <code>info</code> will be nil, implying that you are setting your *chosenImage为零。

关于ios - 为什么禁用 allowsEditing 时,iPhone 上的相机拍摄的全屏照片不会显示在 UIImageview 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19707266/

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