Ios 如何获取当前在uiscrollview中显示的uiimage?

Ios 如何获取当前在uiscrollview中显示的uiimage?,ios,uiscrollview,uiimage,Ios,Uiscrollview,Uiimage,我有下面的代码,它获取一个包含uiimage路径的NSDictionary数组,并将它们逐个添加到uiscrollview - (void)displayAssets:(NSArray*)postAssets //configured for search { for (UIView *v in self.scrollview.subviews) { [v removeFromSuperview]; } CGRect workingFrame = sel

我有下面的代码,它获取一个包含uiimage路径的NSDictionary数组,并将它们逐个添加到uiscrollview

- (void)displayAssets:(NSArray*)postAssets //configured for search
{
    for (UIView *v in self.scrollview.subviews) {
        [v removeFromSuperview];
    }

    CGRect workingFrame = self.scrollview.frame;
    workingFrame.origin.x = 0;

    self.scrollview.delegate = self;
    //    self.scrollview.contentInset=UIEdgeInsetsMake(10.0,0.0,10.0,0.0);

    NSString *pathOfNoImageFile = [[NSBundle mainBundle] pathForResource:@"noimage" ofType:@"png"];

    if (postAssets == nil || [postAssets count] == 0) {

        UIImage *noImage = [UIImage imageWithContentsOfFile:pathOfNoImageFile];
        UIImageView *imageview = [[UIImageView alloc] initWithImage:noImage];

        [imageview setContentMode:UIViewContentModeScaleAspectFit];
        imageview.frame = workingFrame;
        [self.scrollview addSubview:imageview];
    }
    else
    {

            //at this moment we have an actual NSArray/NSDictionarry of images that has keys etc.

            for (NSDictionary *asset in postAssets) //we have to differentiate between images and videos in future
            {

                //ASSUMING FIRST VALUE IN ASSETS IS AN Image   THIS WILL NEED REFACTORING FOR VIDEOS LATER
                NSString * assetID = [asset valueForKeyPath:@"id"];
                NSString * imageURL = [NSString stringWithFormat:@"%@post/7777/images/%@.jpg", WEB_SERVICE_BASE_URL, assetID];

                UIImage *waitingImage = [UIImage imageWithContentsOfFile:pathOfNoImageFile];
                UIImageView *imageview = [[UIImageView alloc] init];

                [imageview  setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:waitingImage];

                [imageview setContentMode:UIViewContentModeScaleAspectFit];
                imageview.frame = workingFrame;

                [self.scrollview addSubview:imageview];
                workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width;
            }
            [self.scrollview setContentSize:CGSizeMake(workingFrame.origin.x, workingFrame.size.height)];



    }

    //    [[self tableView] reloadData];

}
我在同一个文件的另一个函数中尝试做的是获取第一个uiimage或当前显示的uiimage,但我无法这样做。Uiscrollview似乎没有一种方法可以让人们深入到各个视图,以便获得uiimage。我看了其他的SO问题,但它们似乎很复杂

有人能指引我吗?我对UIScrollView相当陌生


谢谢

假设每个图像与滚动视图的宽度相同,您可以:

保留指向您添加的UIImages的指针数组,然后使用scrollview.contentOffset.x/scrollview.bounds.size.width获取当前显示图像的索引

使用scroller.contentOffset作为点调用hitTest:cgpointpointwithevent:UIEvent*event-这将返回此时的最高视图,即UIImageView