【问题标题】:Xcode: UIScrollView with Paging TweakXcode:带有分页调整的 UIScrollView
【发布时间】:2011-10-01 07:03:10
【问题描述】:

我在网上找到了一个很棒的教程,它向您展示了如何浏览不同的页面,很好。这里是教程的链接:http://www.iosdevnotes.com/2011/03/uiscrollview-paging/

我的问题是,我如何调整他的代码,以便加载不同的独立视图或我创建的视图控制器文件,而不是加载“颜色”?就像我看到它从 NSArray 加载它的信息一样,但是您如何对其进行编码以便在该数组中包含视图或视图控制器,并且您是否必须添加其他特殊的东西才能实现这一点?

这是我在他的教程中引用的代码,它在实现文件中:

- (void)viewDidLoad {
    [super viewDidLoad];

    pageControlBeingUsed = NO;

    NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil];
    for (int i = 0; i < colors.count; i++) {
        CGRect frame;
        frame.origin.x = self.scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;

        UIView *subview = [[UIView alloc] initWithFrame:frame];
        subview.backgroundColor = [colors objectAtIndex:i];
        [self.scrollView addSubview:subview];
        [subview release];
    }

    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);

    self.pageControl.currentPage = 0;
    self.pageControl.numberOfPages = colors.count;
}

【问题讨论】:

    标签: ios xcode uiviewcontroller uiscrollview paging


    【解决方案1】:

    作为一个快速的想法,您可以尝试创建一个数组或类似的视图而不是颜色。

    然后在 for 循环中从数组中取出视图并在 addSubView: 消息中使用它。

    这适用于一些视图,但不能很好地扩展。

    我做了类似的事情,但 UIImageViews 能够滚动一些图像。

    【讨论】:

    • 是的,我正在寻求帮助。我最多只有 2 或 3 个视图,但我不知道要使用正确的“代码”来实现这一点。那么如果我包含视图而不是颜色,我的 NSArray 会是什么样子?
    • 查看 Apple 的示例代码。如果你需要的话,有一个叫做滚动。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    • 2011-08-02
    • 1970-01-01
    • 2013-05-21
    相关资源
    最近更新 更多