|
20 | 20 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
21 | 21 | // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22 | 22 |
|
23 |
| -#include <math.h> |
24 |
| - |
25 | 23 | #import "TOCropView.h"
|
26 | 24 | #import "TOCropOverlayView.h"
|
27 | 25 | #import "TOCropScrollView.h"
|
@@ -217,7 +215,7 @@ - (void)setup
|
217 | 215 | [self addSubview:self.foregroundContainerView];
|
218 | 216 |
|
219 | 217 | self.foregroundImageView = [[UIImageView alloc] initWithImage:self.image];
|
220 |
| - self.foregroundImageView.backgroundColor = [UIColor colorWithWhite:1.0f alpha:1.0f]; |
| 218 | + self.foregroundImageView.backgroundColor = [UIColor colorWithWhite:1.0f alpha:1.0f]; |
221 | 219 | self.foregroundImageView.layer.minificationFilter = kCAFilterTrilinear;
|
222 | 220 | [self.foregroundContainerView addSubview:self.foregroundImageView];
|
223 | 221 |
|
@@ -322,8 +320,8 @@ - (void)layoutInitialImage
|
322 | 320 | //Set the crop box to the size we calculated and align in the middle of the screen
|
323 | 321 | CGRect frame = CGRectZero;
|
324 | 322 | frame.size = self.hasAspectRatio ? cropBoxSize : scaledSize;
|
325 |
| - frame.origin.x = bounds.origin.x + floorf((CGRectGetWidth(bounds) - frame.size.width) * 0.5f); |
326 |
| - frame.origin.y = bounds.origin.y + floorf((CGRectGetHeight(bounds) - frame.size.height) * 0.5f); |
| 323 | + frame.origin.x = floorf(bounds.origin.x + floorf((CGRectGetWidth(bounds) - frame.size.width) * 0.5f)); |
| 324 | + frame.origin.y = floorf(bounds.origin.y + floorf((CGRectGetHeight(bounds) - frame.size.height) * 0.5f)); |
327 | 325 | self.cropBoxFrame = frame;
|
328 | 326 |
|
329 | 327 | //set the fully zoomed out state initially
|
@@ -418,7 +416,9 @@ - (void)matchForegroundToBackground
|
418 | 416 | return;
|
419 | 417 |
|
420 | 418 | //We can't simply match the frames since if the images are rotated, the frame property becomes unusable
|
421 |
| - self.foregroundImageView.frame = [self.backgroundContainerView.superview convertRect:self.backgroundContainerView.frame toView:self.foregroundContainerView]; |
| 419 | + self.foregroundImageView.frame = [self.backgroundContainerView.superview |
| 420 | + convertRect:self.backgroundContainerView.frame |
| 421 | + toView:self.foregroundContainerView]; |
422 | 422 | }
|
423 | 423 |
|
424 | 424 | - (void)updateCropBoxFrameWithGesturePoint:(CGPoint)point
|
@@ -783,20 +783,23 @@ - (void)updateToImageCropFrame:(CGRect)imageCropframe
|
783 | 783 |
|
784 | 784 | // Zoom into the scroll view to the appropriate size
|
785 | 785 | self.scrollView.zoomScale = self.scrollView.minimumZoomScale * scale;
|
786 |
| - |
| 786 | + |
| 787 | + CGSize contentSize = self.scrollView.contentSize; |
| 788 | + self.scrollView.contentSize = CGSizeMake(floorf(contentSize.width), floorf(contentSize.height)); |
| 789 | + |
787 | 790 | // Work out the size and offset of the upscaled crop box
|
788 | 791 | CGRect frame = CGRectZero;
|
789 |
| - frame.size = (CGSize){scaledCropSize.width * scale, scaledCropSize.height * scale}; |
| 792 | + frame.size = (CGSize){floorf(scaledCropSize.width * scale), floorf(scaledCropSize.height * scale)}; |
790 | 793 |
|
791 | 794 | //set the crop box
|
792 | 795 | CGRect cropBoxFrame = CGRectZero;
|
793 | 796 | cropBoxFrame.size = frame.size;
|
794 |
| - cropBoxFrame.origin.x = CGRectGetMidX(bounds) - (frame.size.width * 0.5f); |
795 |
| - cropBoxFrame.origin.y = CGRectGetMidY(bounds) - (frame.size.height * 0.5f); |
| 797 | + cropBoxFrame.origin.x = floorf(CGRectGetMidX(bounds) - (frame.size.width * 0.5f)); |
| 798 | + cropBoxFrame.origin.y = floorf(CGRectGetMidY(bounds) - (frame.size.height * 0.5f)); |
796 | 799 | self.cropBoxFrame = cropBoxFrame;
|
797 | 800 |
|
798 |
| - frame.origin.x = (scaledOffset.x * scale) - self.scrollView.contentInset.left; |
799 |
| - frame.origin.y = (scaledOffset.y * scale) - self.scrollView.contentInset.top; |
| 801 | + frame.origin.x = ceilf((scaledOffset.x * scale) - self.scrollView.contentInset.left); |
| 802 | + frame.origin.y = ceilf((scaledOffset.y * scale) - self.scrollView.contentInset.top); |
800 | 803 | self.scrollView.contentOffset = frame.origin;
|
801 | 804 | }
|
802 | 805 |
|
|
0 commit comments