             self.imageHeight = scale * (self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0)
             let imageX = ((self.referenceFrame.size.width - self.imageWidth) / 2) + self.referenceFrame.origin.x
             let imageY = ((self.referenceFrame.size.height - self.imageHeight) / 2) + self.referenceFrame.origin.y
-            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
+            referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
         case .ScaleAspectFill:
             let scale = max(widthRatio, heightRatio)
             self.imageWidth = scale * (self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0)
             self.imageHeight = scale * (self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0)
             let imageX = ((self.referenceFrame.size.width - self.imageWidth) / 2) + self.referenceFrame.origin.x
             let imageY = ((self.referenceFrame.size.height - self.imageHeight) / 2) + self.referenceFrame.origin.y
-            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
+            referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
         case .ScaleToFill:
             self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
             self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
-            self.referenceFrame = self.referenceImageView.frame
+            referenceFrame = self.referenceImageView.frame
         case .Top:
             self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
             self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
             let imageX = ((self.referenceFrame.size.width - self.imageWidth) / 2) + self.referenceFrame.origin.x
             let imageY = self.referenceFrame.origin.y
-            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
+            referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
         case .Bottom:
             self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
             self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
             let imageX = ((self.referenceFrame.size.width - self.imageWidth) / 2) + self.referenceFrame.origin.x
             let imageY = (self.referenceFrame.size.height + self.referenceFrame.origin.y) - self.imageHeight
-            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
+            referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
         case .Left:
             self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
             self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
             let imageX = self.referenceFrame.origin.x
             let imageY = ((self.referenceFrame.size.height - self.imageHeight) / 2) + self.referenceFrame.origin.y
-            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
+            referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
         case .Right:
             self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
             self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
             let imageX = (self.referenceFrame.origin.x + self.referenceFrame.size.width) - self.imageWidth
             let imageY = ((self.referenceFrame.size.height - self.imageHeight) / 2) + self.referenceFrame.origin.y
-            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
+            referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
         case .Center:
             self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
             self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
             let imageX = self.referenceImageView.frame.origin.x + ((self.referenceImageView.frame.width - self.imageWidth) / 2)
             let imageY = self.referenceImageView.frame.origin.y + ((self.referenceImageView.frame.height - self.imageHeight) / 2)
-            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
+            referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
         case .TopLeft:
             self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
             self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
             let imageX = self.referenceFrame.origin.x
             let imageY = self.referenceFrame.origin.y
-            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
+            referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
         case .TopRight:
             self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
             self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
             let imageX = self.referenceFrame.origin.x + self.referenceFrame.size.width - self.imageWidth
             let imageY = self.referenceFrame.origin.y
-            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
+            referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
         case .BottomLeft:
             self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
             self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
             let imageX = self.referenceFrame.origin.x
             let imageY = self.referenceFrame.origin.y + self.referenceFrame.size.height - self.imageHeight
-            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
+            referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
         case .BottomRight:
             self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
             self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
             let imageX = self.referenceFrame.origin.x + self.referenceFrame.size.width - self.imageWidth
             let imageY = self.referenceFrame.origin.y + self.referenceFrame.size.height - self.imageHeight
-            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
+            referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
         case .Redraw:
             self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
             self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
-            self.referenceFrame = self.referenceImageView.frame
-        }
+            referenceFrame = self.referenceImageView.frame
+        }
+        
+        return referenceFrame
         
     }
     func centerScrollViewContents() {

        }
        self.imageView.frame = contentsFrame
    }
}
        print("Scroll view content size while zooming: \(self.scrollView.contentSize)")
    }
    
    //MARK:- Helper Methods
    
    func setReferenceFrameForMode(mode: UIViewContentMode) -> CGRect{
        
        
        let widthRatio = self.referenceImageView.bounds.size.width / (self.referenceImageView.image != nil ? (self.referenceImageView.image?.size.width)! : self.referenceImageView.bounds.size.width)
        let heightRatio = self.referenceImageView.bounds.size.height / (self.referenceImageView.image != nil ? (self.referenceImageView.image?.size.height)! : self.referenceImageView.bounds.size.height)
        let referenceFrame : CGRect
        
        switch(mode) {
        case .ScaleAspectFit:
