[英]iPhone SDK: UIScrollView does not scroll
我只是无法让我的滚动视图实际滚动..一切都显示正常,除了它只是不会滚动.....这是我的代码:
- (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];
}
我该如何解决这个问题?
contentSize
必须大于scrollview的框架才能滚动任何内容。 :)
在这种情况下,它们都是(320, 600)
320,600 (320, 600)
所以将scrollView的init更改为
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
您的scrollview框架应该小于contentSize,因此只有您可以使scrollview可滚动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.