I'm having a problem with UIScrollView
, not sure if it's a bug or not, but it's occurring when I implement a UIScrollView
with its delegate
and a zoomable / pannable image.
First off, when I pan the image, it's possible that the contentOffset
can be a non integer value (.5). For certain zoomScales
, when I pan the image all the way to the edge, it's falling a half pixel shy of reaching the edge because of this.
It's a very small thing, but in my app I have to drag objects around the screen, and if I drag an object to the corner, you can notice it.
I've implemented the following to try and correct the problem and make it so the contentOffset
has to be a whole value:
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
if (targetContentOffset->x != ceilf(targetContentOffset->x))
{
if (velocity.x > 0)
{
targetContentOffset->x = ceilf(targetContentOffset->x);
}
else
{
targetContentOffset->x = floorf(targetContentOffset->x);
}
}
if (targetContentOffset->y != ceilf(targetContentOffset->y))
{
if (velocity.y > 0)
{
targetContentOffset->y = ceilf(targetContentOffset->y);
}
else
{
targetContentOffset->y = floorf(targetContentOffset->y);
}
}
}
However, it doesn't seem to be working as my targetContentOffset
is completely different than the contentOffset
property.
Does anyone a) why this bug is occurring or b) how to fix it using the above delegate method or some other means?