【问题标题】:Why are Fullscreen Photos taken by Camera on iphone not displayed in UIImageview when allowsEditing is disabled?为什么禁用允许编辑时,iPhone 上的相机拍摄的全屏照片不显示在 UIImageview 中?
【发布时间】:2013-10-31 13:02:54
【问题描述】:

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

问题是它只有在我设置时才适用于我的情况

picker.allowsEditing = YES

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

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

这里是需要的方法:

- (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];}

【问题讨论】:

    标签: ios iphone uiimageview camera


    【解决方案1】:

    它与 UIImagePickerControllerDelegate 协议有关

    当您将allowsEditing 设置为yes 时,您将在委托方法触发时开始接收一个充满有用信息的NSDictionary:

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

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

    通过将allowsEditing 设置为NO,委托方法将为info 参数传递nil。

    您可以通过在方法中设置断点来确认这一点,进入并观察 info 将为 nil,这意味着您将 *chosenImage 设置为 nil。

    【讨论】:

    • 好的,我明白了。所以我想用这种方法我不能拍全屏照片?还是有其他功能可以删除那个限光方块?
    • 我可能应该在这里更具体一点,返回的字典中更改的是“编辑信息键”,而不是未经编辑的信息本身。当您传入 UIImagePickerControllerEditedImage 时,您特别要求编辑后的图像,而我认为您想要的是 UIImagePickerControllerOriginalImage。
    • 您可以通过设置断点并深入研究该变量来快速查看 info 字典中的内容。
    • 我发现我的错误不是“UIImage *chosenImage = info[UIImagePickerControllerEditedImage];”我必须使用“UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];”
    • 啊,你也这么评论了。谢谢你。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-17
    相关资源
    最近更新 更多