0

没有视图控制器或任何界面构建器,我只想用代码构建它。我有方法设置,您可以单击按钮转到相机胶卷,但现在我不知道下一步该做什么。我需要一种选择图像的方法,它允许我将图像添加到图像视图中。任何关于做什么的提示将不胜感激。

 - (void)viewDidLoad {
   UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)];
[self.view addSubview: imgView];


UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
           action:@selector(aMethod)
 forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:button];
}

-(void)aMethod{

UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsImageEditing = YES;
[[self navigationController] presentModalViewController:picker animated:YES];
 }
4

2 回答 2

1

我认为这可能会有所帮助:-

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

作为代表imagePickerController

您可以通过信息键获取图像:-

UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

有关更多信息,请参阅此链接

info是一个dictionary包含原始图像编辑后的图像,如果选择了图像;或电影的文件系统URL(如果选择了电影)。还包含任何相关的dictionary编辑信息。编辑信息键dictionary中列出了此键。

于 2013-01-22T02:28:34.860 回答
0

以前的答案是正确的......但这是另一种看待它的方式......

只要您的代码调用您的相册,您将需要的下一步是:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}

这会将返回的信息放入您选择的 imageView .....

您发布的代码中的内容是打开您的照片库....净步骤是说好的....我已经完成了选择我的媒体....我将如何处理它?

于 2013-01-22T03:28:28.670 回答