Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kikko088

macrumors member
Original poster
Oct 13, 2010
77
0
Italy
I need to have the possibility to put the selected line on the middle of frame, so if I select the first or the last row this row need to ben on the center and not clip to the top (or to the bottom) of the tableview, something like an uipickerview, this is my code on scrollwillendDragging:

- (void)scrollViewWillEndDragging: (UIScrollView *)scrollView
withVelocity: (CGPoint)velocity
targetContentOffset: (inout CGPoint *)targetContentOffset {

CGFloat rowHeight = [delegate rowHeightForMyPickerView:self];
CGFloat floatVal = targetContentOffset->y / rowHeight;
NSInteger rounded = (NSInteger)(lround(floatVal));
targetContentOffset->y = rounded * rowHeight;
NSLog(@"Offset: %f Float: %f Row: %d",targetContentOffset->y,floatVal,rounded);
[delegate myPickerView:self isOverRow:rounded];
}
with this code I create snap effect but rounded is not the correct row, changing the first and last cell height with a double height the problem disappear but I don't like this way.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.