【问题标题】:iPhone SDK: UIScrollView does not scrolliPhone SDK:UIScrollView 不滚动
【发布时间】:2011-03-25 11:56:03
【问题描述】:

我只是无法让我的滚动视图真正滚动.. 一切都显示正常,只是它不会滚动.....这是我的代码:

- (void)viewDidLoad {
    [super viewDidLoad];

    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 600)];
    scrollView.contentSize = CGSizeMake(320, 600);
    scrollView.scrollEnabled = YES;
    scrollView.clipsToBounds = YES;
    [self.view addSubview:scrollView];

    planView = [[WorkoutPlanView alloc] initWithImage:[UIImage imageNamed:@"WorkoutTable.png"]];
    planView2 = [[WorkoutPlanView alloc] initWithImage:[UIImage imageNamed:@"WorkoutTable.png"]];
    planView2.frame = CGRectMake(0, 164, 320, 165);
    planView3 = [[WorkoutPlanView alloc] initWithImage:[UIImage imageNamed:@"WorkoutTable.png"]];
    planView3.frame = CGRectMake(0, 328, 320, 165);
    planView4 = [[WorkoutPlanView alloc] initWithImage:[UIImage imageNamed:@"WorkoutTable.png"]];
    planView4.frame = CGRectMake(0, 505, 320, 165);
    [scrollView addSubview:planView];
    [scrollView addSubview:planView2];
    [scrollView addSubview:planView3];
    [scrollView addSubview:planView4];
}

我该如何解决这个问题?

【问题讨论】:

    标签: iphone objective-c uiscrollview uiimageview


    【解决方案1】:

    你的滚动视图框架应该小于 contentSize,所以只有你可以让滚动视图滚动。

    【讨论】:

      【解决方案2】:

      contentSize 必须大于滚动视图的框架才能滚动。 :)

      在这种情况下,它们都是 (320, 600),所以将你的 scrollView 的 init 更改为

      UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
      

      【讨论】:

      • 不错的 pop850。加一!
      猜你喜欢
      • 2012-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-03
      • 1970-01-01
      • 2011-03-16
      相关资源
      最近更新 更多