iOS - Horizontally sliding items

有些话、适合烂在心里 提交于 2019-12-03 09:13:32

You'll want to use a UIScrollView for that. You add your "pieces of paper" -- which I assume will be views (UIImageViews perhaps?) -- as subviews, and set the contentSize property of the scroll view to fit them all. You might also want to set the showsHorizontalScrollIndicator property of the scroll view to NO, to hide the scroller.

Off the top of my head, I imagine something like this:

UIScrollView *aScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
aScrollView.showsHorizontalScrollIndicator = NO;

CGFloat paperWidth = 320;
NSUInteger numberOfPapers = 5;
for (NSUInteger i = 0; i < numberOfPapers; i++) {
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(paperWidth * i, 0, paperWidth, aScrollView.bounds.size.height)];
    imageView.image = LOAD_IMAGE_HERE...;
    [aScrollView addSubview:imageView];
}

CGSize contentSize = CGSizeMake(paperWidth * numberOfPapers, aScrollView.bounds.size.height);
aScrollView.contentSize = contentSize;

[self.view addSubview:aScrollView];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!