From d673c670af8a0562d7e60b56893c51a48dab0651 Mon Sep 17 00:00:00 2001 From: Raunak Roy Date: Fri, 21 Feb 2014 17:43:52 -0800 Subject: [PATCH 1/3] centering scroll content if it is smaller than the destination size --- RSMoveAndScaleController.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/RSMoveAndScaleController.m b/RSMoveAndScaleController.m index 975debb..38fe61b 100644 --- a/RSMoveAndScaleController.m +++ b/RSMoveAndScaleController.m @@ -133,6 +133,16 @@ - (void)limitScrollViewInBounds offset.y = MAX(MIN(offset.y, t.y), -threshold.y); offset.x = MAX(MIN(offset.x, t.x), -threshold.x); + + //center items if they are smaller than destination size + if (self.destinationSize.width > size.width) { + offset.x -= roundf((self.destinationSize.width - size.width)/2);; + } + + if (self.destinationSize.height > size.height) { + offset.y -= roundf((self.destinationSize.height - size.height)/2);; + } + _scrollView.contentOffset = offset; _scrollView.contentInset = UIEdgeInsetsMake(-offset.y, -offset.x, 0, 0); } From e6a3dda490b3e1f03ab646f9efb4432d01771748 Mon Sep 17 00:00:00 2001 From: Raunak Roy Date: Wed, 26 Mar 2014 15:17:38 -0700 Subject: [PATCH 2/3] fixing style changes --- RSMoveAndScaleController.m | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/RSMoveAndScaleController.m b/RSMoveAndScaleController.m index 38fe61b..0dbfb48 100644 --- a/RSMoveAndScaleController.m +++ b/RSMoveAndScaleController.m @@ -130,19 +130,19 @@ - (void)limitScrollViewInBounds CGFloat scale = (1 - 1 / _scrollView.zoomScale); // NSLog(@"scale %f offset:%@", scale, NSStringFromCGPoint(offset)); CGPoint t = scale == 1 ? threshold : CGPointMake(threshold.x + size.width * scale, threshold.y + size.height * scale); - - offset.y = MAX(MIN(offset.y, t.y), -threshold.y); - offset.x = MAX(MIN(offset.x, t.x), -threshold.x); - - //center items if they are smaller than destination size - if (self.destinationSize.width > size.width) { - offset.x -= roundf((self.destinationSize.width - size.width)/2);; - } - - if (self.destinationSize.height > size.height) { - offset.y -= roundf((self.destinationSize.height - size.height)/2);; - } - + + offset.y = MAX(MIN(offset.y, t.y), - threshold.y); + offset.x = MAX(MIN(offset.x, t.x), - threshold.x); + + //center items if they are smaller than destination size + if (self.destinationSize.width > size.width) { + offset.x -= roundf((self.destinationSize.width - size.width) / 2); + } + + if (self.destinationSize.height > size.height) { + offset.y -= roundf((self.destinationSize.height - size.height) / 2); + } + _scrollView.contentOffset = offset; _scrollView.contentInset = UIEdgeInsetsMake(-offset.y, -offset.x, 0, 0); } From ec23efd6dd65f2663ca2d93b42e2a3655b74e74e Mon Sep 17 00:00:00 2001 From: Raunak Roy Date: Wed, 26 Mar 2014 15:19:38 -0700 Subject: [PATCH 3/3] fixing style changes --- RSMoveAndScaleController.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RSMoveAndScaleController.m b/RSMoveAndScaleController.m index 0dbfb48..573350c 100644 --- a/RSMoveAndScaleController.m +++ b/RSMoveAndScaleController.m @@ -131,8 +131,8 @@ - (void)limitScrollViewInBounds // NSLog(@"scale %f offset:%@", scale, NSStringFromCGPoint(offset)); CGPoint t = scale == 1 ? threshold : CGPointMake(threshold.x + size.width * scale, threshold.y + size.height * scale); - offset.y = MAX(MIN(offset.y, t.y), - threshold.y); - offset.x = MAX(MIN(offset.x, t.x), - threshold.x); + offset.y = MAX(MIN(offset.y, t.y), -threshold.y); + offset.x = MAX(MIN(offset.x, t.x), -threshold.x); //center items if they are smaller than destination size if (self.destinationSize.width > size.width) {