iOS - 水平滑动项目 [英] iOS - Horizontally sliding items

查看:139
本文介绍了iOS - 水平滑动项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些照片,就像长方形纸一样。我想把它放在屏幕的中央,当用户用手指向左或向右滑动时(让我们说左边),那张纸应该向左(用手指),从右边应该是新的一块有一些新信息的论文。

I have some picture, let's say like rectangular piece of paper. I want to position it on the center of the screen, and when user slides left or right with its finger (let's say left), that piece of paper should go left (with the finger), and from the right should come new piece of paper with some new information.

我希望我的描述不会引起混淆。我想这个功能应该很容易用iOS SDK,我只是不知道该用什么...

I hope that my description isn't confusing. I guess that this functionality should be easy to do with iOS SDK, I just don't know what to use ...

感谢您的帮助;)

推荐答案

您需要使用 UIScrollView 。你添加你的纸片 - 我认为它将是视图( UIImageView 或许?) - 作为子视图,并设置 contentSize 滚动视图的属性以适应它们。您可能还想将滚动视图的 showsHorizo​​ntalScrollIndicator 属性设置为 NO ,以隐藏滚动条。

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

这篇关于iOS - 水平滑动项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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