UIScrollView ContentOffset does not reach screen edge

I have a problem with UIScrollView , not sure if this is an error or not, but it occurs when I implement UIScrollView with its delegate and scalable / paged image.

First, when I pan the image, it is possible that the contentOffset may not be an integer value (.5). Surely zoomScales , when I swing the image to the edge, it drops half a pixel, shy to get to the edge because of this.

This is a very small thing, but in my application I need to drag objects around the screen, and if I drag an object to a corner, you may notice it.

I applied the following to try to fix the problem and make contentOffset have to be an integer 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 does not work, since my targetContentOffset completely different from the contentOffset property.

Does anyone a) why this error occurs or b) how to fix it using the above delegation method or some other means?

+4
source share
1 answer

Alternatively, implementing this method may work for you.

 -(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView 

If you look at your comments below, you may need to implement several methods. The one above, or the one indicated in the other answer, when it slows down to a stop, just to make sure that you are touching the state of the edge, and the method that you should already process for speed points.

+2
source

Source: https://habr.com/ru/post/1415661/


All Articles