在新屏幕上加载我的图像

时间:2014-04-28 17:56:19

标签: ios image loading

我有我想要的所有工作,你可以在图片中看到的视图,我不希望图像加载在同一个屏幕上,我怎么能让它加载到一个新的屏幕。我已经尝试了一些教程,但我还没有运气

从图库加载的图像是背景中的砖墙。

我想在新屏幕中加载它的原因是我可以放一个新的工具栏,它可以让我拖动图像并将它们叠加在从较高的图像或用相机拍摄的图像上方

提前致谢并且抱歉询问听起来如此简单的事情,我对这一切都很陌生。

http://imageshack.com/a/img845/4808/9lz8.png

- (IBAction)selectPhoto:(UIButton *)sender {

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[self presentViewController:picker animated:YES completion:NULL];


}

#pragma mark - Image Picker Controller delegate methods

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

UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;

[picker dismissViewControllerAnimated:YES completion:NULL];

}

如何在didFinishPickingMediaWithInfo

时打开新屏幕

如果您需要查看更多代码,请告诉我哪些,我不确定您需要查看哪些代码:)谢谢您的回复。

2 个答案:

答案 0 :(得分:0)

如果您希望在新屏幕上加载图像,则需要创建第二个viewController,并将imageView添加到该viewController。

然后在你的didFinishPicking方法中,而不是将图像设置为当前ViewController的imageView,实例化一个新的imageController,设置新viewController的imageView属性,然后如果你&#39将新的viewController推送到导航堆栈;重新使用导航控制器。如果您不使用导航控制器,则可以按模式推送第二个视图控制器。

所以在你的didFinishPicking方法中,它将是

UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
NewViewController *newViewController = [[NewViewController alloc] init];
newViewController.imageView.image = chosenImage; //or whatever the imageView property is called of your new view controller
[self presentViewController:newViewController animated:YES completion:nil];

(我还没有对这段代码进行测试 - 它已经脱离了我的头脑,所以读者谨慎建议,这是模态方法)

答案 1 :(得分:0)

试试吧:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:^{
  // I think you should not call `presentViewController` newViewController at this screen because it maybe be destroyed
  // So, call newViewController at parentClass by delegate of block
  // and assign new image to the screen which need to show
}];

}