在我的应用程序中,我从 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];}
最佳答案
它与 UIImagePickerControllerDelegate 协议(protocol)有关
当您设置allowsEditing
时为 yes,那么当委托(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 - 为什么当禁用 allowedEditing 时,iPhone 上的相机拍摄的全屏照片不会显示在 UIImageview 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19707266/