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

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
Code:
- (void)scrollViewDidScroll:(UIScrollView *)theScrollView
{
    CGFloat width = self.scrollView.bounds.size.width;
    int currentPage = (self.scrollView.contentOffset.x + width/2.0f) / width;
    self.pageControl.currentPage = currentPage;
}

The x property here 'contentOffset.x' is listed in the documentation as geomagnetic data expressed as microteslas???

If this is the case, then dividing by a float promotes this unit value to a float also?

If this is the case, then how is an int returned? are the figures after the decimal point simply dropped?
 
The calculation is carried out using the float type. The result is then converted to an int when it's stored in your currentPage variable (or any other use that involves an int type).

The conversion to an int truncates the fractional part; "round toward zero" is the specific floating-point rounding mode, IIRC.
 
The calculation is carried out using the float type. The result is then converted to an int when it's stored in your currentPage variable (or any other use that involves an int type).

The conversion to an int truncates the fractional part; "round toward zero" is the specific floating-point rounding mode, IIRC.

there to save the day again chown! i owe you
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.