There are many ways to achieve the effect. Assuming you have self.view initialized from a nib file and a regular UIView, you can put this code in viewDidLoad:
- (void)viewDidLoad { CGRect tvFrame = self.view.frame; tvFrame.origin = CGPointZero; UITableView* tv = [[UITableView alloc] initWithFrame:self.view.frame]; tv.delegate = self; tv.dataSource = self; tv.showsVerticalScrollIndicator = NO; [self.view addSubview:tv]; CGRect svFrame = CGRectMake(290, 10, 30, 400); UIScrollView* sv = [[UIScrollView alloc] initWithFrame:svFrame]; sv.contentSize = CGSizeMake(10, 780); sv.showsVerticalScrollIndicator = NO; sv.bounces = YES; CGRect vFrame = CGRectMake(10, 380, 10, 20); UIView* v = [[UIView alloc] initWithFrame:vFrame]; v.backgroundColor = [UIColor blueColor]; [sv addSubview:v]; [self.view addSubview:sv]; [super viewDidLoad]; }
This will create a table with a narrow scroll view with a blue rectangle above the table. Now you can scroll both types of scrolling (the table also represents scrolling) independently.
Then you will have to configure delegates and receive scroll events through UIScrollViewDelegate. When one of the scroll views starts dragging, you need to start adjusting the offset of the other scroll view.
source share