在我的应用程序中,我从 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];}