检测图像对象用户正在scrollviewdidscroll中查看 [英] detect image object user is viewing in scrollviewdidscroll

查看:129
本文介绍了检测图像对象用户正在scrollviewdidscroll中查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测用户所在的图像对象?

How can i detect which image object user is on?

尝试以这种方式这样做但不起作用

Trying to do it this way but it is not working

 - (void)scrollViewDidScroll:(UIScrollView *)sender {

// [_imageScrollView contentOffset];

CGFloat imageViewWidth = _imageScrollView.frame.size.width;
//int currentPage = floor((_imageScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
NSInteger image = (NSInteger)floor((self.imageScrollView.contentOffset.x * 2.0f + imageViewWidth) / (imageViewWidth * 2.0f));
[_imageScrollView contentOffset];

//self.imageView.image = image;
}

编辑:如果我这样使用它仍然无法正常工作

If i use it like this still it is not working

- (void)LongPress:(UILongPressGestureRecognizer*)gestureRecognizer{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){
    CGPoint location = [gesture locationInView:_imageView];
    CGFloat imageViewWidth = _imageScrollView.frame.size.width;
    int imageView = floor((_imageScrollView.contentOffset.x - imageViewWidth / 2) / imageViewWidth) + 1;

    NSLog(@"contains point?? - %d", CGRectContainsPoint(_imageView.bounds, location));


    if (CGRectContainsPoint(_imageView.bounds, [self.view convertPoint:location toView:_imageView]))
    {

        UIImageWriteToSavedPhotosAlbum(_image, self, @selector(image: didFinishSavingWithError:contextInfo:), nil);
    }
}}

如果我遗漏了什么,请告诉我。

Please let me know if i m missing something.

谢谢

推荐答案

- (void)scrollViewDidScroll:(UIScrollView *)sender 
{
    CGFloat pageWidth = scrollView.frame.size.width;
    int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth);
}

只有启用了分页后,上述方法才能为您提供正确的当前页码 UIScrollView

Above method give you correct current page number, only when you have enabled the paging of UIScrollView.

这篇关于检测图像对象用户正在scrollviewdidscroll中查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆