Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As Wubao mentioned, you have to use the <code>UIScrollViewDelegate</code>. But you have to check, which scrollView is dragging / active at the moment. Because else you will have the problem that you will get delegate callbacks from both scrollviews and they will give their change to each other at the same time resulting in an endless loop / in endless scrolling.</p> <p>In detail, you have to check: <code>- (void)scrollViewDidScroll:(UIScrollView *)scrollView</code></p> <p>But you have to remember the previous offset, so you do know the change of the value. (Or your views have the same height. Then you could just use <code>contentSize.height-offset</code> as the offset for the other view.</p> <p>I'll try to write it down a little bit (untested):</p> <pre><code>@interface ViewController () &lt;UITableViewDelegate,UIScrollViewDelegate&gt; // instances of your tableviews @property (nonatomic, strong) UITableView *tableLeft; @property (nonatomic, strong) UITableView *tableRight; // track active table @property (nonatomic, strong) UIScrollView* activeScrollView; // helpers for contentoffset tracking @property (nonatomic, assign) CGFloat lastOffsetLeft; @property (nonatomic, assign) CGFloat lastOffsetRight; @end @implementation ViewController - (void) viewDidLoad { [super viewDidLoad]; self.tableLeft.delegate = self; self.tableRight.delegate = self; } – (void) scrollViewWillBeginDragging: (UIScrollView*) scrollView { self.activeScrollView = scrollView; self.tableViewRight.userInterActionEnabled = (self.tableViewRight == scrollView); self.tableViewLeft.userInterActionEnabled = (self.tableViewLeft == scrollView); } - (void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { if(!decelerate) { self.activeScrollView = nil; self.tableViewRight.userInterActionEnabled = YES; self.tableViewLeft.userInterActionEnabled = YES; } } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { self.activeScrollView = nil; self.tableViewRight.userInterActionEnabled = YES; self.tableViewLeft.userInterActionEnabled = YES; } - (void) scrollViewDidScroll:(UIScrollView *)scrollView { if(self.activeScrollView == self.tableViewLeft) { CGFloat changeLeft = self.tableViewLeft.contentOffset.y - self.lastOffsetLeft; self.tableViewRight.contentOffset.y += changeLeft; } else if (self.activeScrollView == self.tableViewRight) { CGFloat changeRight = self.tableViewRight.contentOffset.y - self.lastOffsetRight; self.tableViewLeft.contentOffset.y += changeRight; } self.lastOffsetLeft = self.tableViewLeft.contentOffset.y; self.lastOffsetRight = self.tableViewRight.contentOffset.y; } @end </code></pre> <p>Thats it basically. It also locks the not active scrollview. Because scrolling both would result in ugly behaviour. Also <code>contentOffset.y += changeLeft;</code> wont work probably. You have to create a new CGPoint/CGSize.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload