使用第二个滚动视图来控制主滚动视图。我添加了一个渐变以便能够看到滚动。
#import <QuartzCore/QuartzCore.h>
@implementation ScrollViewController {
UIScrollView *mainScrollView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect mainScrollViewRect = CGRectMake(0, 0, self.view.bounds.size.width - 100, self.view.bounds.size.height);
mainScrollView = [[UIScrollView alloc] initWithFrame:mainScrollViewRect];
mainScrollView.scrollEnabled = NO;
mainScrollView.contentSize = CGSizeMake(self.view.bounds.size.width - 100, 1000);
[self.view addSubview:mainScrollView];
CAGradientLayer* gradientLayer = [CAGradientLayer layer];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1, 1);
gradientLayer.frame = CGRectMake(0, 0, mainScrollView.contentSize.width, mainScrollView.contentSize.height);
gradientLayer.colors = @[(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor]];
[mainScrollView.layer insertSublayer:gradientLayer atIndex:0];
CGRect toolbarRect = CGRectMake(self.view.bounds.size.width - 100, 0, 100, self.view.bounds.size.height);
UIScrollView *toolbarScrollView = [[UIScrollView alloc] initWithFrame:toolbarRect];
toolbarScrollView.delegate = self;
toolbarScrollView.contentSize = CGSizeMake(0, 1000);
toolbarScrollView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:toolbarScrollView];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
mainScrollView.contentOffset = scrollView.contentOffset;
}
@end