我覺得我在這裏丟失了超級明顯的東西。設置了內容大小的UIScrollView無法滾動超出幀邊界
我有一個故事板的UIScrollView,帶有視圖控制器的插座。
我以編程方式添加一系列視圖,並設置滾動視圖的內容大小。
儘管我已經將scrollview的內容高度設置爲非常高的值,但我無法滾動到視圖邊界之外。
設置後正在打印內容大小和幀大小。以及scrollview滾動時的contentoffset.y。
這裏是控制檯輸出的一個例子:
2013-09-24 21:54:34.531 [Redacted] scrollView frame size: 320.000000,460.000000
2013-09-24 21:54:34.531 [Redacted] scrollView content size: 0.000000,10000.000000
2013-09-24 21:54:36.259 [Redacted] scroll to: 6.000000
2013-09-24 21:54:36.275 [Redacted] scroll to: 17.000000
2013-09-24 21:54:36.291 [Redacted] scroll to: 29.000000
2013-09-24 21:54:36.308 [Redacted] scroll to: 41.000000
2013-09-24 21:54:36.325 [Redacted] scroll to: 52.000000
2013-09-24 21:54:36.341 [Redacted] scroll to: 65.000000
2013-09-24 21:54:36.358 [Redacted] scroll to: 74.000000
2013-09-24 21:54:36.375 [Redacted] scroll to: 84.000000
2013-09-24 21:54:36.392 [Redacted] scroll to: 90.000000
2013-09-24 21:54:36.408 [Redacted] scroll to: 95.000000
2013-09-24 21:54:36.425 [Redacted] scroll to: 100.000000
2013-09-24 21:54:36.441 [Redacted] scroll to: 103.000000
2013-09-24 21:54:36.459 [Redacted] scroll to: 107.000000
2013-09-24 21:54:36.475 [Redacted] scroll to: 110.000000
2013-09-24 21:54:36.492 [Redacted] scroll to: 114.000000
2013-09-24 21:54:36.509 [Redacted] scroll to: 118.000000
2013-09-24 21:54:36.525 [Redacted] scroll to: 122.000000
2013-09-24 21:54:36.542 [Redacted] scroll to: 126.000000
2013-09-24 21:54:36.558 [Redacted] scroll to: 130.000000
2013-09-24 21:54:36.575 [Redacted] scroll to: 134.000000
2013-09-24 21:54:36.592 [Redacted] scroll to: 141.000000
2013-09-24 21:54:36.609 [Redacted] scroll to: 147.000000
2013-09-24 21:54:36.625 [Redacted] scroll to: 152.000000
2013-09-24 21:54:36.642 [Redacted] scroll to: 156.000000
2013-09-24 21:54:36.659 [Redacted] scroll to: 159.000000
2013-09-24 21:54:36.676 [Redacted] scroll to: 160.000000
2013-09-24 21:54:36.776 [Redacted] scroll to: 161.000000
2013-09-24 21:54:37.010 [Redacted] scroll to: 162.000000
2013-09-24 21:54:37.026 [Redacted] scroll to: 168.000000
2013-09-24 21:54:37.043 [Redacted] scroll to: 179.000000
2013-09-24 21:54:37.060 [Redacted] scroll to: 195.000000
2013-09-24 21:54:37.077 [Redacted] scroll to: 207.000000
2013-09-24 21:54:37.097 [Redacted] scroll to: 209.000000
2013-09-24 21:54:37.112 [Redacted] scroll to: 219.000000
2013-09-24 21:54:37.129 [Redacted] scroll to: 223.000000
2013-09-24 21:54:37.145 [Redacted] scroll to: 222.000000
2013-09-24 21:54:37.162 [Redacted] scroll to: 218.000000
2013-09-24 21:54:37.179 [Redacted] scroll to: 212.000000
2013-09-24 21:54:37.195 [Redacted] scroll to: 204.000000
2013-09-24 21:54:37.212 [Redacted] scroll to: 195.000000
2013-09-24 21:54:37.229 [Redacted] scroll to: 186.000000
2013-09-24 21:54:37.245 [Redacted] scroll to: 177.000000
2013-09-24 21:54:37.262 [Redacted] scroll to: 168.000000
2013-09-24 21:54:37.279 [Redacted] scroll to: 160.000000
2013-09-24 21:54:37.296 [Redacted] scroll to: 152.000000
2013-09-24 21:54:37.312 [Redacted] scroll to: 145.000000
2013-09-24 21:54:37.329 [Redacted] scroll to: 138.000000
2013-09-24 21:54:37.346 [Redacted] scroll to: 133.000000
2013-09-24 21:54:37.362 [Redacted] scroll to: 127.000000
2013-09-24 21:54:37.379 [Redacted] scroll to: 122.000000
2013-09-24 21:54:37.396 [Redacted] scroll to: 118.000000
2013-09-24 21:54:37.412 [Redacted] scroll to: 114.000000
2013-09-24 21:54:37.429 [Redacted] scroll to: 111.000000
2013-09-24 21:54:37.445 [Redacted] scroll to: 108.000000
2013-09-24 21:54:37.462 [Redacted] scroll to: 105.000000
2013-09-24 21:54:37.479 [Redacted] scroll to: 103.000000
2013-09-24 21:54:37.496 [Redacted] scroll to: 101.000000
2013-09-24 21:54:37.512 [Redacted] scroll to: 99.000000
2013-09-24 21:54:37.529 [Redacted] scroll to: 98.000000
2013-09-24 21:54:37.545 [Redacted] scroll to: 96.000000
2013-09-24 21:54:37.562 [Redacted] scroll to: 95.000000
2013-09-24 21:54:37.579 [Redacted] scroll to: 94.000000
2013-09-24 21:54:37.595 [Redacted] scroll to: 93.000000
2013-09-24 21:54:37.629 [Redacted] scroll to: 92.000000
2013-09-24 21:54:37.645 [Redacted] scroll to: 91.000000
2013-09-24 21:54:37.695 [Redacted] scroll to: 90.000000
2013-09-24 21:54:37.745 [Redacted] scroll to: 89.000000
2013-09-24 21:54:37.862 [Redacted] scroll to: 88.000000
2013-09-24 21:54:38.381 [Redacted] scroll to: 89.000000
2013-09-24 21:54:38.397 [Redacted] scroll to: 108.000000
2013-09-24 21:54:38.414 [Redacted] scroll to: 127.000000
2013-09-24 21:54:38.431 [Redacted] scroll to: 150.000000
2013-09-24 21:54:38.448 [Redacted] scroll to: 164.000000
2013-09-24 21:54:38.464 [Redacted] scroll to: 182.000000
2013-09-24 21:54:38.481 [Redacted] scroll to: 195.000000
2013-09-24 21:54:38.499 [Redacted] scroll to: 213.000000
2013-09-24 21:54:38.516 [Redacted] scroll to: 222.000000
2013-09-24 21:54:38.533 [Redacted] scroll to: 224.000000
2013-09-24 21:54:38.550 [Redacted] scroll to: 222.000000
2013-09-24 21:54:38.566 [Redacted] scroll to: 217.000000
2013-09-24 21:54:38.583 [Redacted] scroll to: 209.000000
2013-09-24 21:54:38.599 [Redacted] scroll to: 201.000000
2013-09-24 21:54:38.616 [Redacted] scroll to: 192.000000
2013-09-24 21:54:38.633 [Redacted] scroll to: 183.000000
2013-09-24 21:54:38.650 [Redacted] scroll to: 174.000000
2013-09-24 21:54:38.666 [Redacted] scroll to: 166.000000
2013-09-24 21:54:38.683 [Redacted] scroll to: 157.000000
2013-09-24 21:54:38.699 [Redacted] scroll to: 150.000000
2013-09-24 21:54:38.716 [Redacted] scroll to: 143.000000
2013-09-24 21:54:38.733 [Redacted] scroll to: 137.000000
2013-09-24 21:54:38.749 [Redacted] scroll to: 131.000000
2013-09-24 21:54:38.766 [Redacted] scroll to: 126.000000
2013-09-24 21:54:38.783 [Redacted] scroll to: 121.000000
2013-09-24 21:54:38.799 [Redacted] scroll to: 117.000000
2013-09-24 21:54:38.816 [Redacted] scroll to: 113.000000
2013-09-24 21:54:38.833 [Redacted] scroll to: 110.000000
2013-09-24 21:54:38.849 [Redacted] scroll to: 107.000000
2013-09-24 21:54:38.866 [Redacted] scroll to: 105.000000
2013-09-24 21:54:38.883 [Redacted] scroll to: 102.000000
2013-09-24 21:54:38.900 [Redacted] scroll to: 100.000000
2013-09-24 21:54:38.916 [Redacted] scroll to: 99.000000
2013-09-24 21:54:38.933 [Redacted] scroll to: 97.000000
2013-09-24 21:54:38.950 [Redacted] scroll to: 96.000000
2013-09-24 21:54:38.966 [Redacted] scroll to: 95.000000
2013-09-24 21:54:38.983 [Redacted] scroll to: 94.000000
2013-09-24 21:54:39.000 [Redacted] scroll to: 93.000000
2013-09-24 21:54:39.016 [Redacted] scroll to: 92.000000
2013-09-24 21:54:39.049 [Redacted] scroll to: 91.000000
2013-09-24 21:54:39.083 [Redacted] scroll to: 90.000000
2013-09-24 21:54:39.150 [Redacted] scroll to: 89.000000
2013-09-24 21:54:39.267 [Redacted] scroll to: 88.000000
2013-09-24 21:54:43.145 [Redacted] scroll to: 91.000000
2013-09-24 21:54:43.162 [Redacted] scroll to: 97.000000
2013-09-24 21:54:43.178 [Redacted] scroll to: 103.000000
2013-09-24 21:54:43.195 [Redacted] scroll to: 109.000000
2013-09-24 21:54:43.212 [Redacted] scroll to: 115.000000
2013-09-24 21:54:43.229 [Redacted] scroll to: 120.000000
2013-09-24 21:54:43.245 [Redacted] scroll to: 124.000000
2013-09-24 21:54:43.262 [Redacted] scroll to: 127.000000
2013-09-24 21:54:43.279 [Redacted] scroll to: 130.000000
2013-09-24 21:54:43.296 [Redacted] scroll to: 131.000000
2013-09-24 21:54:43.312 [Redacted] scroll to: 133.000000
2013-09-24 21:54:43.329 [Redacted] scroll to: 135.000000
2013-09-24 21:54:43.345 [Redacted] scroll to: 136.000000
2013-09-24 21:54:43.374 [Redacted] scroll to: 137.000000
2013-09-24 21:54:43.664 [Redacted] scroll to: 138.000000
2013-09-24 21:54:43.681 [Redacted] scroll to: 139.000000
2013-09-24 21:54:43.697 [Redacted] scroll to: 143.000000
2013-09-24 21:54:43.714 [Redacted] scroll to: 149.000000
2013-09-24 21:54:43.731 [Redacted] scroll to: 155.000000
2013-09-24 21:54:43.748 [Redacted] scroll to: 161.000000
2013-09-24 21:54:43.764 [Redacted] scroll to: 166.000000
2013-09-24 21:54:43.781 [Redacted] scroll to: 169.000000
2013-09-24 21:54:43.798 [Redacted] scroll to: 172.000000
2013-09-24 21:54:43.814 [Redacted] scroll to: 174.000000
2013-09-24 21:54:43.831 [Redacted] scroll to: 177.000000
2013-09-24 21:54:43.848 [Redacted] scroll to: 178.000000
2013-09-24 21:54:43.865 [Redacted] scroll to: 180.000000
2013-09-24 21:54:43.887 [Redacted] scroll to: 181.000000
2013-09-24 21:54:43.914 [Redacted] scroll to: 183.000000
2013-09-24 21:54:43.948 [Redacted] scroll to: 184.000000
2013-09-24 21:54:43.981 [Redacted] scroll to: 186.000000
2013-09-24 21:54:43.998 [Redacted] scroll to: 187.000000
2013-09-24 21:54:44.015 [Redacted] scroll to: 188.000000
2013-09-24 21:54:44.031 [Redacted] scroll to: 189.000000
2013-09-24 21:54:44.048 [Redacted] scroll to: 190.000000
2013-09-24 21:54:44.065 [Redacted] scroll to: 191.000000
2013-09-24 21:54:44.082 [Redacted] scroll to: 192.000000
2013-09-24 21:54:44.116 [Redacted] scroll to: 194.000000
2013-09-24 21:54:44.149 [Redacted] scroll to: 195.000000
2013-09-24 21:54:44.182 [Redacted] scroll to: 196.000000
2013-09-24 21:54:44.216 [Redacted] scroll to: 197.000000
2013-09-24 21:54:44.266 [Redacted] scroll to: 198.000000
2013-09-24 21:54:44.283 [Redacted] scroll to: 199.000000
2013-09-24 21:54:44.299 [Redacted] scroll to: 200.000000
2013-09-24 21:54:44.316 [Redacted] scroll to: 202.000000
2013-09-24 21:54:44.349 [Redacted] scroll to: 203.000000
2013-09-24 21:54:44.366 [Redacted] scroll to: 204.000000
2013-09-24 21:54:44.449 [Redacted] scroll to: 205.000000
2013-09-24 21:54:44.500 [Redacted] scroll to: 206.000000
2013-09-24 21:54:44.601 [Redacted] scroll to: 207.000000
2013-09-24 21:54:44.932 [Redacted] scroll to: 189.000000
2013-09-24 21:54:44.949 [Redacted] scroll to: 174.000000
2013-09-24 21:54:44.966 [Redacted] scroll to: 161.000000
2013-09-24 21:54:44.982 [Redacted] scroll to: 151.000000
2013-09-24 21:54:44.999 [Redacted] scroll to: 141.000000
2013-09-24 21:54:45.016 [Redacted] scroll to: 133.000000
2013-09-24 21:54:45.032 [Redacted] scroll to: 126.000000
2013-09-24 21:54:45.049 [Redacted] scroll to: 121.000000
2013-09-24 21:54:45.066 [Redacted] scroll to: 116.000000
2013-09-24 21:54:45.082 [Redacted] scroll to: 112.000000
2013-09-24 21:54:45.099 [Redacted] scroll to: 108.000000
2013-09-24 21:54:45.116 [Redacted] scroll to: 105.000000
2013-09-24 21:54:45.133 [Redacted] scroll to: 102.000000
2013-09-24 21:54:45.149 [Redacted] scroll to: 100.000000
2013-09-24 21:54:45.166 [Redacted] scroll to: 98.000000
2013-09-24 21:54:45.183 [Redacted] scroll to: 97.000000
2013-09-24 21:54:45.200 [Redacted] scroll to: 96.000000
2013-09-24 21:54:45.216 [Redacted] scroll to: 94.000000
2013-09-24 21:54:45.233 [Redacted] scroll to: 93.000000
2013-09-24 21:54:45.266 [Redacted] scroll to: 92.000000
2013-09-24 21:54:45.283 [Redacted] scroll to: 91.000000
2013-09-24 21:54:45.316 [Redacted] scroll to: 90.000000
2013-09-24 21:54:45.366 [Redacted] scroll to: 89.000000
2013-09-24 21:54:45.483 [Redacted] scroll to: 88.000000
正如你所看到的,我不能滾動超過200多。
我對iOS並不陌生,以前曾使用過滾動視圖,所以我覺得我必須錯過一些非常明顯的東西。
任何幫助非常感謝,有一個緊迫的最後期限!
編輯:添加代碼:
checkboxes = [[NSMutableArray alloc] init];
{
// Just indented scope for tidyness, no functional meaning
[checkboxes addObject:[self createCheckboxWithLabel:@"Oil Level Checked"
atY:190]];
[checkboxes addObject:[self createCheckboxWithLabel:@"Coolant Level Checked"
atY:240]];
[checkboxes addObject:[self createCheckboxWithLabel:@"Tyre pressures & tread dept checked"
atY:290]];
[checkboxes addObject:[self createCheckboxWithLabel:@"Warning beacon & horn operating"
atY:340]];
[checkboxes addObject:[self createCheckboxWithLabel:@"Lights & indicators working & clean"
atY:390]];
[checkboxes addObject:[self createCheckboxWithLabel:@"Screen was & wipers operational"
atY:440]];
[checkboxes addObject:[self createCheckboxWithLabel:@"Mirrors undamaged & clean"
atY:490]];
[checkboxes addObject:[self createCheckboxWithLabel:@"Road Tax & MOD discs present & valid"
atY:540]];
[checkboxes addObject:[self createCheckboxWithLabel:@"PPE in vechile"
atY:590]];
[checkboxes addObject:[self createCheckboxWithLabel:@"Fire Extinguisher & First Aid kit present"
atY:640]];
[checkboxes addObject:[self createCheckboxWithLabel:@"Wheel nuts checked with torque wrench"
atY:690]];
}
for(WpCheckboxWithLabelView *checkbox in checkboxes){
[scrollView addSubview: checkbox];
}
// Set content size of scrollview
scrollView.contentSize = CGSizeMake(0, 10000);
scrollView.delegate = self;
NSLog(@"scrollView frame size: %f,%f", scrollView.frame.size.width, scrollView.frame.size.height);
NSLog(@"scrollView content size: %f,%f", scrollView.contentSize.width, scrollView.contentSize.height);
我已經將代碼添加到OP中。我只是創建一系列自定義視圖。它們超出了滾動視圖框架,因此我將內容大小設置得相當大,但我仍然無法在框架外滾動。 (如OP中的控制檯輸出所示)。 – Autonomy