【问题标题】:passing selected image from uiscrollView to other viewController将所选图像从 uiscrollView 传递到其他 viewController
【发布时间】:2013-12-12 23:01:04
【问题描述】:

有一个视图控制器,它有一个UIViewControllerUIScrollView。 我将UItapgesturerecognizer 添加到滚动视图中,以便在点击滚动视图上的图像时调用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

【问题讨论】:

  • 你试过什么?这是一个几乎每天都在 StackOverflow 上被问和回答的问题,此外还有一百万个关于该主题的教程。你在哪里卡住了?
  • 如果您知道合适的教程,请告诉我;我坚持将图像路径到下一个视图

标签: ios iphone uiscrollview uitapgesturerecognizer


【解决方案1】:

很难确切地知道自己在做什么。如果我是正确的,您想在用户单击图像时创建一个新的视图控制器吗?这是您可以执行此操作的一种方法。

1) 你可以创建一个视图控制器的实例来传递该图像,然后将该实例的图像设置为选定的图像。像这样的:

@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];

}

希望这对你有用。希望这是有道理的,就像我说的那样,基于模糊的问题很难回答。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多