【问题标题】:how to scroll list of uiviews in a UIScrollView which will be in bottom of the page?如何滚动页面底部的 UIScrollView 中的 uiview 列表?
【发布时间】:2010-12-07 07:22:05
【问题描述】:

我想在我的 ipad 应用程序的 uiscrollview 中放置 uiviews 列表而不是 uiimageviews 作为内容。我使用 imageviews 滚动图像,但我需要 uiviews 作为必须水平滚动的子视图列表?我试过了通过 Interfacebuilder 在 uiscrollview 中添加 uiview,但是在运行应用程序时,我只能看到一个 uiview,因为所有剩余的视图都不存在。请帮我解决这个问题。


我这样尝试过,但它仍然没有显示视图,并且我以编程方式尝试了 UIScrollView 的尺寸和其中的视图,如下面的代码:-

scrollView.frame=CGRectMake(0, 604, 728,365);
scrollView.bounces = YES;
scrollView.pagingEnabled = YES;
scrollView.backgroundColor = [UIColor darkGrayColor];
scrollView.delegate = self;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.userInteractionEnabled = YES;


UIView *subView1=[[UIView alloc]initWithFrame:CGRectMake(20, 604, 758,365)];
subView1.backgroundColor=[UIColor blueColor];
[scrollView addSubview:subView1];
[subView1 release];
UIView *subView2=[[UIView alloc]initWithFrame:CGRectMake(828, 604, 758,365)];
subView2.backgroundColor=[UIColor blueColor];
[scrollView addSubview:subView2];
[subView2 release];
[scrollView release];

【问题讨论】:

  • 你设置了它的内容大小,我认为你增加了 interfacebuilder 中的滚动视图大小,给 contentsize 更多然后滚动视图,例如如果你 interfacebuilder 滚动视图大小是 (0,0,600,460) ,然后在 viewdid 加载中给出滚动视图内容大小,就像这样 cgsizemake(900,460) 它会起作用
  • 如果仍然没有看到剩余的视图,请告诉我
  • 是的,我试过这样仍然没有显示视图。我还尝试以编程方式尝试滚动视图的尺寸和其中的视图,如下面的代码:
  • scrollView.frame=CGRectMake(0, 604, 728,365); scrollView.bounces = YES; scrollView.pagingEnabled = YES; scrollView.backgroundColor = [UIColor darkGrayColor]; scrollView.delegate = 自我; scrollView.showsHorizo​​ntalScrollIndicator = NO; scrollView.userInteractionEnabled = YES;
  • UIView *subView1=[[UIView alloc]initWithFrame:CGRectMake(20, 604, 758,365)]; subView1.backgroundColor=[UIColor blueColor]; [scrollView addSubview:subView1]; [subView1 发布]; UIView *subView2=[[UIView alloc]initWithFrame:CGRectMake(828, 604, 758,365)]; subView2.backgroundColor=[UIColor blueColor]; [scrollView addSubview:subView2]; [subView2 发布]; [scrollView 发布];

标签: iphone objective-c ios4


【解决方案1】:
UIView *subView1=[[UIView alloc]initWithFrame:CGRectMake(20, 604, 758,365)];
subView1.backgroundColor=[UIColor blueColor];
[scrollView addSubview:subView1];
[subView1 release];
UIView *subView2=[[UIView alloc]initWithFrame:CGRectMake(828, 604, 758,365)];
subView2.backgroundColor=[UIColor blueColor];
[scrollView addSubview:subView2];
[scrollView setContentSize:CGSizeMake(758+758, 365+365)]]
[subView2 release];
[scrollView release];

[scrollView setContentSize:CGSizeMake(758+758, 365+365)]]

您需要设置 contentsize 以便能够滚动并查看所有子视图。

【讨论】:

  • 老大,我这样做了,它现在正在显示,但它没有水平滚动,它处于诊断滚动状态。
  • [scrollView setContentSize:CGSizeMake(758, 365+365)]] 试试这个
  • 我试过 [758+758,365]; .现在它正在水平滚动,但我只能看到第一个视图。第二个视图没有出现
【解决方案2】:

您需要在需要时添加 UIView。您需要使用编程方法来添加 UIView。您应该看看 Apple 提供的 PageControl 示例代码。我希望你能得到你的答案。

【讨论】:

    【解决方案3】:

    我尝试使用 [758+758,365]; .现在它正在水平滚动,但我只能看到第一个视图。第二个视图没有出现。

    scrollView.frame=CGRectMake(0, 604, 728,365);
    scrollView.bounces = YES;
    scrollView.pagingEnabled = YES;
    scrollView.backgroundColor = [UIColor darkGrayColor];
    scrollView.delegate = self;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.userInteractionEnabled = YES;
    [scrollView setContentSize:CGSizeMake(1600,365)];
    
    
    UIView *subView1=[[UIView alloc]initWithFrame:CGRectMake(20, 604, 758,365)];
    subView1.backgroundColor=[UIColor blueColor];
    subView1.frame=scrollView.bounds;
    [subView1 addSubview:myImageView];
    [scrollView addSubview:subView1];
    
    
    UIView *subView2=[[UIView alloc]initWithFrame:CGRectMake(828, 604, 758,365)];
    subView2.backgroundColor=[UIColor blackColor];
    subView2.frame=scrollView.bounds;
    
    [scrollView addSubview:subView2];
    
        [subView1 release];
    [subView2 release];
    
    
    [scrollView release];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-03
      • 2013-01-19
      • 2019-10-05
      • 1970-01-01
      • 1970-01-01
      • 2015-11-21
      • 2013-10-27
      • 1970-01-01
      相关资源
      最近更新 更多