Xcode、UIscrollView 和分页

发布于 2024-12-03 08:19:50 字数 107 浏览 1 评论 0原文

我是初学者,我需要知道如何在 UIScrollView 中放入多个页面。这些页面应包含交互元素,例如按钮、视频以及文本和图像。如果您能给我任何教程链接或一些线索,我将不胜感激。

问候。

I am a beginner, I need to know how I can put in a UIScrollView multiple pages. These pages should contain interactive elements such as buttons,video and also text and images. I would appreciate any link to a tutorial or some clue that you could give me.

Regards.

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

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

发布评论

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

评论(3

半衬遮猫 2024-12-10 08:19:50
  1. 如果您想要水平显示,请将滚动视图的 pagingEnabled 属性设置为 YES
  2. 使滚动视图的 contentSize 属性 X * width 宽如果您想要垂直分页,则分页或“X * height”高。
  3. 通过为每个页面添加正确的偏移量(“X * 宽度”或“X * 高度”,取决于水平/垂直),将子视图添加到每个“页面”。ž

X 是页面数,从 0 开始。

这里是具有 5 个水平页的示例。

int numberOfPages = 5;
UIScrollView *someScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
someScrollView.pagingEnabled = YES;
someScrollView.contentSize = CGSizeMake(numberOfPages * someScrollView.frame.size.width, someScrollView.frame.size.height);
[self.view addSubview:someScrollView];
[someScrollView release];

for (int i = 0; i < numberOfPages; i++) {
    UILabel *tmpLabel = [[UILabel alloc] initWithFrame:CGRectMake(i * someScrollView.frame.size.width + 20,
                                                                  20,
                                                                  someScrollView.frame.size.width - 40,
                                                                  20)];
    tmpLabel.textAlignment = UITextAlignmentCenter;
    tmpLabel.text = [NSString stringWithFormat:@"This is page %d", i];
    [someScrollView addSubview:tmpLabel];
    [tmpLabel release];
}
  1. set your scroll view's pagingEnabled property to YES
  2. make your scroll view's contentSizeproperty X * width wide if you want horizontal paging or `X * height' tall if you want vertical paging.
  3. add subview to each "page" by adding them with the right offset for each page (`X * width' or 'X * height' depending on horizontal/vertical).ž

X is a number of pages, starting with 0.

Here is a sample with 5 horizontal pages.

int numberOfPages = 5;
UIScrollView *someScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
someScrollView.pagingEnabled = YES;
someScrollView.contentSize = CGSizeMake(numberOfPages * someScrollView.frame.size.width, someScrollView.frame.size.height);
[self.view addSubview:someScrollView];
[someScrollView release];

for (int i = 0; i < numberOfPages; i++) {
    UILabel *tmpLabel = [[UILabel alloc] initWithFrame:CGRectMake(i * someScrollView.frame.size.width + 20,
                                                                  20,
                                                                  someScrollView.frame.size.width - 40,
                                                                  20)];
    tmpLabel.textAlignment = UITextAlignmentCenter;
    tmpLabel.text = [NSString stringWithFormat:@"This is page %d", i];
    [someScrollView addSubview:tmpLabel];
    [tmpLabel release];
}
最近可好 2024-12-10 08:19:50

听起来页面控制就是您正在寻找的控制。

以下是示例代码的链接:LiNk

Sounds like page control is the one that you are looking for.

Here is the link with sample code: LiNk

倒带 2024-12-10 08:19:50

您需要在 UIScrollView 上设置 2 个属性,以便实现平滑的分页滚动。

[scroller setPagingEnabled:YES];
[scroller setContentSize:CGSizeMake(width, height)];
/* width here would be your view's width times the amount of pages you want. */

You need to set 2 properties on your UIScrollView in order to have a smooth paging scroll.

[scroller setPagingEnabled:YES];
[scroller setContentSize:CGSizeMake(width, height)];
/* width here would be your view's width times the amount of pages you want. */
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文