Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone xcode,如何添加一个图像视图,该视图根据我在“摄影机滚动”中选择的内容更改图像?_Iphone_Ios_Objective C_Xcode_Camera - Fatal编程技术网

Iphone xcode,如何添加一个图像视图,该视图根据我在“摄影机滚动”中选择的内容更改图像?

Iphone xcode,如何添加一个图像视图,该视图根据我在“摄影机滚动”中选择的内容更改图像?,iphone,ios,objective-c,xcode,camera,Iphone,Ios,Objective C,Xcode,Camera,没有视图控制器或任何interfacebuilder,我只想用代码构建它。我有一个方法设置,你可以点击按钮进入相机滚动,但现在我不知道下一步该怎么做。我需要一种方法来选择一个图像,它将允许我添加到一个图像视图的图像。任何关于如何做的建议都将不胜感激 - (void)viewDidLoad { UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)]; [self.view

没有视图控制器或任何interfacebuilder,我只想用代码构建它。我有一个方法设置,你可以点击按钮进入相机滚动,但现在我不知道下一步该怎么做。我需要一种方法来选择一个图像,它将允许我添加到一个图像视图的图像。任何关于如何做的建议都将不胜感激

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

我认为这有助于:-

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

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

UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
更多信息请参见此

信息是
包含原始图像编辑图像
字典
,如果已拾取图像;或者电影的文件系统URL,如果选择了电影。
词典
还包含任何相关的编辑信息。此
词典
的键列在编辑信息键中

前面的答案是正确的……但这里有另一种方式来看待它

只要您有代码调用相册,下一步就需要:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
这将把返回的信息放入您选择的imageView


你发布的代码中的内容是打开你的照片库……最后一步是说“好吧”……我已经选好了媒体……我要用它做什么?

我不认为这有什么帮助。@FalconHawk-你为什么不这么想???就因为他给了你一个正确的链接,让你自己读出来,而你想要确切的两行吗?这就是我说的哈哈哈