如何在iPhone中使用Slider而不是Scrollviewer Vertical Bar?

时间:2011-06-13 08:37:33

标签: iphone

我使用Slider控件而不是使用Scrollviewer Vertical Bar。 但它运作不正常。

scrollViewer.contentSize = CGSizeMake(320, (ThumbnailSizeHeight + PADDING) * [list count]);
slider.maximumValue =  (ThumbnailSizeHeight + PADDING) * [list count];  

请指正。

1 个答案:

答案 0 :(得分:0)

contentSize大于滚动查看器的帧大小之前,您不需要滚动。所以,

CGFloat scrollableHeight = (ThumbnailSizeHeight + PADDING) * [list count] - scrollViewer.frame.size.height;
if ( scrollableHeight <= 0 ) {
    slider.enabled = NO; // or use the `hidden` property
} else {
    slider.enabled = YES; // or .hidden based on what you do in `if`
    slider.maximumValue = scrollableHeight;
}

稍后在UIControlEventValueChanged

上的滑块的界面操作上
- (IBAction)sliderValueChanged:(UISlider *)slider {
    scrollViewer.contentOffset = CGPointMake(0, slider.value);
}