带有 UIPageControl 的 UIView

发布于 2024-10-14 06:11:13 字数 445 浏览 4 评论 0原文

在页面控制方面我是一个初学者,这就是为什么我不能100%确定我的标题是否符合我想要的。我想制作一个 UIPageControl,当用户在屏幕上滑动时,视图会切换到另一个视图,并且屏幕底部的 UIPageController 会自行更新。另外,为了使我的请求更加混乱,我希望屏幕底部有一个选项卡栏,该选项卡栏会随着视图的变化而保持不变。

The Iconfactory 的 Ramp Champ 就是一个很好的例子: http://img.slidetoplay.com/screenshots/ramp-champ_5.jpg

底部的栏当屏幕上的其余项目移动时保持不动。做到这一点最简单的方法是什么?

编辑:我知道我必须使用 UISrollView,我只是不知道如何去实现它......

I'm a beginner when it comes to page control, and that's why I'm not sure 100% if my title agrees with what I want. I want to make a UIPageControl that when the user swipes on the screen, the view would switch over to another view and the UIPageController at the bottom of the screen would update itself. Also, to make my request even more confusing, I want a tab bar at the bottom of the screen that would stay put as the views change.

A great example of this is The Iconfactory's Ramp Champ:
http://img.slidetoplay.com/screenshots/ramp-champ_5.jpg

The bar at the bottom stays put while the rest of the items on the screen moves. What would be the easiest way to do this?

EDIT: I know I have to use a UISrollView, I just don't know how to go about implementing it...

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

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

发布评论

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

评论(2

梦冥 2024-10-21 06:11:14

您需要使用 UIScrollView

假设你有一个名为scrollView的命名ivar

    int amountOfFrames = 10;
    scrollView.pagingEnabled = TRUE;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * amountOfFrames, scrollView.frame.size.height);
     scrollView.delegate = self;

然后你需要实现所需的委托方法,以便你可以更新你的页面控件

- (void)scrollViewDidScroll:(UIScrollView *)sender 
{
    // Switch the indicator when more than 50% of the previous/next page is visible
    CGFloat pageWidth = scrollView.frame.size.width;
    int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    pageControl.currentPage = page; 
}

你需要将你想要滚动的任何内容放在这些scrollview中,最好是延迟加载到其中,如果内容您将显示需要大量堆内存,请使用scrollviewDidScroll在所需位置删除和添加内容

You need to use a UIScrollView

Assuming you have a named ivar called scrollView

    int amountOfFrames = 10;
    scrollView.pagingEnabled = TRUE;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * amountOfFrames, scrollView.frame.size.height);
     scrollView.delegate = self;

You will then need to implement the required delegate methods, so that you can update your page control

- (void)scrollViewDidScroll:(UIScrollView *)sender 
{
    // Switch the indicator when more than 50% of the previous/next page is visible
    CGFloat pageWidth = scrollView.frame.size.width;
    int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    pageControl.currentPage = page; 
}

You need to place whatever content you want to be scrollable inside these scrollview, ideally lazyload into it, if the content you will displaying will require a lot of heap memory, use the scrollviewDidScroll to remove and add content at the required positions

滥情稳全场 2024-10-21 06:11:13

我相信您正在寻找的实际上是 UIScrollView 将 pagingEnabled 设置为 YES。您可以将滚动视图保留为常规 UITabBar 上方的视图。您将使用 UIPageControl 来获取小点。当 UIScrollView 滚动到页面时,您可以通过实现滚动视图的适当委托方法(可能是 -scrollViewDidScroll:)以编程方式更新它。

假设您有两个 ivars:scrollView 和 pageControl。当您知道滚动视图将有多少页时,您可以设置滚动视图的 contentSize。它应该是滚动视图边界的倍数。例如,如果页数是静态的,您可以在 -viewDidLoad 中对其进行硬编码...

- (void)viewDidLoad {
    // Any other code.

    scrollView.pagingEnabled = YES;
    scrollView.contentSize = CGSizeMake(scrollView.bounds.size.width * 3, scrollView.bounds.size.height); // 3 pages wide.
    scrollView.delegate = self;
}

然后,更新您的小点...

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

    CGFloat pageWidth = scrollView.bounds.size.width;
    NSInteger pageNumber = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    pageControl.currentPage = pageNumber;
}

I believe what you're looking for is actually a UIScrollView with pagingEnabled set to YES. You can leave the scrollview as a view above a regular UITabBar. You'll use a UIPageControl to get the little dots. You can update it programmatically when the UIScrollView scrolls to a page by implementing an appropriate delegate method of the scroll view, maybe -scrollViewDidScroll:.

Assume you have two ivars: scrollView and pageControl. When you know how many pages your scroll view will have, you can set the contentSize of scrollView. It should be a multiple of the scrollView's bounds. For example, if the number of pages is static you can hardcode it in your -viewDidLoad...

- (void)viewDidLoad {
    // Any other code.

    scrollView.pagingEnabled = YES;
    scrollView.contentSize = CGSizeMake(scrollView.bounds.size.width * 3, scrollView.bounds.size.height); // 3 pages wide.
    scrollView.delegate = self;
}

Then, to update your little dots...

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

    CGFloat pageWidth = scrollView.bounds.size.width;
    NSInteger pageNumber = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    pageControl.currentPage = pageNumber;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文