iPhone SDK:UIScrollView无法滚动。

9

我无法让我的滚动视图实际滚动。除此之外,一切都正常显示,但它就是无法滚动... 这是我的代码:

- (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];
}

我该如何解决这个问题?

2个回答

20

若想要滚动视图可滚动,则contentSize必须大于滚动视图的框架大小。 :)

在这种情况下,它们都是(320, 600),因此将你的 scrollView 的初始化更改为

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

很棒的发现,pop850。加一! - ouflak

0

你的ScrollView框架应该比ContentSize小,这样才能使ScrollView可滚动。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接