UIPickUP
来源:互联网 发布:淘宝代购是不退换的吗 编辑:程序博客网 时间:2024/06/18 18:04
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
MGPickerScrollView * tv = (MGPickerScrollView *) scrollView;
float offset = scrollView.contentOffset.y;
offset += scrollView.contentInset.top;
if ( (offset < 0) || ((offset +VALUE_HEIGHT) > scrollView.contentSize.height))
{
return;
}
int mod = (int)offset%(int)VALUE_HEIGHT;
float newValue = (mod >= VALUE_HEIGHT/2.0) ? offset+(VALUE_HEIGHT-mod) : offset-mod;
float offValue = (mod >= VALUE_HEIGHT/2.0) ? VALUE_HEIGHT - mod: mod;
//Calculates the indexPath of the cell and set it in the object as property
NSInteger indexPathRow = (int)(newValue/VALUE_HEIGHT);
NSLog(@"offset::%f contentInset.top:: %f mod:: %d, newValue:: %f, indexPathRow:: %d offValue:: %f", scrollView.contentOffset.y, scrollView.contentInset.top, mod, newValue, indexPathRow ,offValue );
UITableViewCell *selectCell = [tv cellForRowAtIndexPath: [NSIndexPath indexPathForRow:indexPathRow inSection:0]];
if (selectCell == nil && indexPathRow <0 ) {
return;
}
if (tv.lastCenterRow >=0 && tv.lastCenterRow != indexPathRow)
{
UITableViewCell *cell = [tvcellForRowAtIndexPath: [NSIndexPathindexPathForRow:tv.lastCenterRowinSection:0]];
cell.textLabel.font = [UIFontfontWithName:FONT_NAME size:14];
cell.textLabel.textColor =TEXT_COLOR;
}
selectCell.textLabel.font = [UIFontfontWithName:FONT_NAME size:((18 - 14)/VALUE_HEIGHT*2*(VALUE_HEIGHT-offValue) + 14 )];
selectCell.textLabel.textColor =SELECTED_TEXT_COLOR;
tv.lastCenterRow = indexPathRow;
}