Created
April 30, 2016 19:34
-
-
Save pronebird/5e2455c67b06bf182f7a8c66649df6ac to your computer and use it in GitHub Desktop.
Capture target content offset when using scrollToRowAtIndexPath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BaseTableView.m | |
// | |
// Created by pronebird on 1/12/16. | |
// Copyright © 2016 pronebird. All rights reserved. | |
// | |
@interface BaseTableView () | |
@property (nonatomic) BOOL isCallingFromScrollToRowAtIndexPath; | |
@property (nonatomic) CGPoint scrollToRowOffset; | |
@end | |
@implementation BaseTableView | |
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated { | |
if(self.isCallingFromScrollToRowAtIndexPath) { | |
self.scrollToRowOffset = contentOffset; | |
} | |
[super setContentOffset:contentOffset animated:animated]; | |
} | |
- (CGPoint)scrollToRowAtIndexPathAndReturnTargetOffset:(NSIndexPath *)indexPath | |
atScrollPosition:(UITableViewScrollPosition)scrollPosition | |
animated:(BOOL)animated | |
{ | |
[self scrollToRowAtIndexPath:indexPath atScrollPosition:scrollPosition animated:animated]; | |
return self.scrollToRowOffset; | |
} | |
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated { | |
self.isCallingFromScrollToRowAtIndexPath = YES; | |
[super scrollToRowAtIndexPath:indexPath atScrollPosition:scrollPosition animated:animated]; | |
self.isCallingFromScrollToRowAtIndexPath = NO; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment