@@ -258,14 +258,27 @@ public class ConfirmViewController: UIViewController, UIScrollViewDelegate {
258258 let normalizedHeight = cropRect. height / imageView. frame. height
259259
260260
261- let normRect = normalizedRect ( CGRect ( x: normalizedX, y: normalizedY, width: normalizedWidth, height: normalizedHeight) , orientation: imageView. image!. imageOrientation)
261+ var normRect = normalizedRect ( CGRect ( x: normalizedX, y: normalizedY, width: normalizedWidth, height: normalizedHeight) , orientation: imageView. image!. imageOrientation)
262262 print ( " NormRect: \( normRect) " )
263263
264- let newRect = CGRect ( x: ( imageView. image!. size. width) * ( 1 - ( normRect. origin. y + normRect. height) ) ,
265- y: ( imageView. image!. size. height) * normRect. origin. x,
266- width: ( imageView. image!. size. width * normRect. height) ,
267- height: ( imageView. image!. size. height * normRect. width) )
268- // Note: Mixing x with height and y with width and flipping y because our image orientation is off by 90 degrees because the iPad's in portrait. In landscape, this fails miserably.
264+ switch imageView. image!. imageOrientation {
265+ case . left:
266+ normRect = CGRect ( x: normRect. origin. y, y: 1 - ( normRect. origin. x + normRect. width) , width: normRect. height, height: normRect. width)
267+ case . right:
268+ normRect = CGRect ( x: 1 - ( normRect. origin. y + normRect. height) , y: normRect. origin. x, width: normRect. height, height: normRect. width)
269+ case . up:
270+ normRect = CGRect ( x: normRect. origin. x, y: normRect. origin. y, width: normRect. width, height: normRect. height)
271+ case . down:
272+ normRect = CGRect ( x: 1 - ( normRect. origin. x + normRect. width) , y: 1 - ( normRect. origin. y + normRect. height) , width: normRect. width, height: normRect. height)
273+ default :
274+ normRect = CGRect ( x: 1 - ( normRect. origin. x + normRect. width) , y: normRect. origin. y, width: normRect. width, height: normRect. height)
275+ }
276+
277+ let newRect = CGRect ( x: ( imageView. image!. size. width) * normRect. origin. x,
278+ y: ( imageView. image!. size. height) * normRect. origin. y,
279+ width: ( imageView. image!. size. width * normRect. width) ,
280+ height: ( imageView. image!. size. height * normRect. height) )
281+
269282 print ( " NewRect: \( newRect) " )
270283 newImage = imageView. image? . crop ( rect: newRect)
271284 }
0 commit comments