将所选图像从uiscrollView传递到其他viewController

时间:2013-12-12 23:01:04

标签: ios iphone uiscrollview uitapgesturerecognizer

有一个视图控制器,其UIViewControllerUIScrollView。 我在滚动视图中添加了UItapgesturerecognizer,以便在点击scrollView上的图像时调用singleTapGessureCaptured方法。 题 我要做的是将图像从选定的UIscrollView(从特定单元格)传递到新的视图控制器。

- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture{

    CGPoint touchPoint = [gesture locationInView:scrollView];

    NSUInteger touchedPage = floorf(touchPoint.x / scrollView.frame.size.width);
    if ([imageArray count] > 1) {

        touchedPage = touchedPage % ([imageArray count] - 1);
    }

    //Push the image to another view

1 个答案:

答案 0 :(得分:0)

很难确切知道你在做什么。如果我更正,您想在用户点击图片时创建新的视图控制器吗?这是你可以做到这一点的一种方式。

1)您可以创建要将图像传递到的View Controller实例,然后将该实例的图像设置为所选图像。像这样:

@interface NewViewControllerToStoreImage : UIViewController

@property (strong, nonatomic) UIImageView *imageView;  //You need to display this image somewhere on the view for the view controller.

- (NewViewControllerToStoreImage *) init;  // you need to write the implementation for this method so your view controller can look the way you want it to.

@end

@implementation NewViewControllerToStoreImage

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)];
}
@end

然后在您创建的方法中。

- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture{

    CGPoint touchPoint = [gesture locationInView:scrollView];

    NSUInteger touchedPage = floorf(touchPoint.x / scrollView.frame.size.width);
    if ([imageArray count] > 1) {

        touchedPage = touchedPage % ([imageArray count] - 1);
    }
    //self.selectedImage is a placer for the image that is selected.  I'm not sure where or how you're storing that selected image.
    UIImage *image = self.selectedImage;

    NewViewControllerToStoreImage *newViewController = [[NewViewControllerToStoreImage alloc] init];
    newViewController.imageView.image = image;

    //Then assuming that you're using a UINavigationController.  This line will push that new view controller onto the navigation controller's view controllers and display it on screen.
    [self.navigationController pushViewController:newViewController animated:YES];

}

希望这适合你。并且希望它有意义,就像我说的那样,根据模糊的问题很难回答。