连续滚动图像

发布于 2025-01-06 06:26:18 字数 80 浏览 4 评论 0原文

我需要在我的项目中连续滚动图像,即从图像的底部开始滚动,继续滚动到顶部应该从底部开始,依此类推,在一种循环中,我该怎么做这?

谢谢

I need in my project to make the scroll an image continuously, ie from the bottom of the image once scrolled by continuing to scroll to the top should start from the base and so on, in a sort of loop, how can I do to do this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感情洁癖 2025-01-13 06:26:18

在此示例中,我总共拍摄了 5 张图像

- (void)viewDidLoad {
        [super viewDidLoad];

        // add the last image (image4) into the first position
        [self addImageWithName:@"image4.jpg" atPosition:0];

        // add all of the images to the scroll view
        for (int i = 1; i < 5; i++) {
            [self addImageWithName:[NSString stringWithFormat:@"image%i.jpg",i] atPosition:i];
        }

        // add the first image (image1) into the last position
        [self addImageWithName:@"image1.jpg" atPosition:5];

        scrollView.contentSize = CGSizeMake(320, 2496);    
        [scrollView scrollRectToVisible:CGRectMake(0,416,320,416) animated:NO]; 
    }

    - (void)addImageWithName:(NSString*)imageString atPosition:(int)position {
        // add image to scroll view
        UIImage *image = [UIImage imageNamed:imageString];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.frame = CGRectMake(0,position*416,320, 416);
        [scrollView addSubview:imageView];
        [imageView release];
    }

来实现委托方法

- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender {    
    NSLog(@"%f",scrollView.contentOffset.y);
    // The key is repositioning without animation      
    if (scrollView.contentOffset.y == 0) {         
        // user is scrolling to the left from image 1 to image 4         
        // reposition offset to show image 4 that is on the right in the scroll view         
        [scrollView scrollRectToVisible:CGRectMake(0,1664,320,416) animated:NO];     
    }    
    else if (scrollView.contentOffset.y == 2080) {         
        // user is scrolling to the right from image 4 to image 1        
        // reposition offset to show image 1 that is on the left in the scroll view         
        [scrollView scrollRectToVisible:CGRectMake(0,416,320,416) animated:NO];         
    } 
}

In this example i am taking total 5 images

- (void)viewDidLoad {
        [super viewDidLoad];

        // add the last image (image4) into the first position
        [self addImageWithName:@"image4.jpg" atPosition:0];

        // add all of the images to the scroll view
        for (int i = 1; i < 5; i++) {
            [self addImageWithName:[NSString stringWithFormat:@"image%i.jpg",i] atPosition:i];
        }

        // add the first image (image1) into the last position
        [self addImageWithName:@"image1.jpg" atPosition:5];

        scrollView.contentSize = CGSizeMake(320, 2496);    
        [scrollView scrollRectToVisible:CGRectMake(0,416,320,416) animated:NO]; 
    }

    - (void)addImageWithName:(NSString*)imageString atPosition:(int)position {
        // add image to scroll view
        UIImage *image = [UIImage imageNamed:imageString];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.frame = CGRectMake(0,position*416,320, 416);
        [scrollView addSubview:imageView];
        [imageView release];
    }

implement delegate method

- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender {    
    NSLog(@"%f",scrollView.contentOffset.y);
    // The key is repositioning without animation      
    if (scrollView.contentOffset.y == 0) {         
        // user is scrolling to the left from image 1 to image 4         
        // reposition offset to show image 4 that is on the right in the scroll view         
        [scrollView scrollRectToVisible:CGRectMake(0,1664,320,416) animated:NO];     
    }    
    else if (scrollView.contentOffset.y == 2080) {         
        // user is scrolling to the right from image 4 to image 1        
        // reposition offset to show image 1 that is on the left in the scroll view         
        [scrollView scrollRectToVisible:CGRectMake(0,416,320,416) animated:NO];         
    } 
}
小霸王臭丫头 2025-01-13 06:26:18

我提供了自动滚动滚动视图的两个参考链接,您也可以在其中获取源代码并将其实现到您的项目中,这是令人惊叹的功能

1) 自动滚动滚动视图

2) 根据您的要求创建了类似画廊的帖子。

希望这篇文章对您有用。

快乐编码
谢谢和问候,

@Samuel

I gives the two reference link for the automatically scroll the scroll view where the you can grap the source code also and implement into your project it's amazing funcationality

1) Automatically scroll the scroll view

2) As par your requirement created post of like wise gallery.

May this post is useful for you.

Happy codeing
Thanks and Regards,

@Samuel

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文