         }
     }
 
+    private func contentSize() -> CGSize {
+        let pages = CGFloat(contentViews.count)
+        return CGSize(width: Constants.leadingMargin * 2 + bounds.size.width * pages + Constants.pageSpace * (pages - 1),
+                      height: bounds.size.height)
+    }
+
+    private func contentViewOffset(index: Int) -> CGPoint {
+        return CGPoint(x: Constants.leadingMargin + (bounds.size.width + Constants.pageSpace) * CGFloat(index),
+                       y: 0.0)
+    }
+
     private func contentViewFrame(index: Int) -> CGRect {
-        return CGRect(x: (bounds.size.width + inbetweenImagesMargin) * CGFloat(index),
-                      y: 0.0,
-                      width: bounds.size.width,
-                      height: bounds.size.height)
-    }
-
-    private func contentViewWithImageModel(_ imageModel: MediaViewerImageModel?, frame: CGRect) -> MediaViewerInteractiveImageView {
-        let contentView = MediaViewerInteractiveImageView(frame: frame)
+        return CGRect(origin: contentViewOffset(index: index),
+                      size: bounds.size)
+    }
+
+    private func contentViewWithImageModel(_ imageModel: MediaViewerImageModel?, index: Int) -> MediaViewerInteractiveImageView {
+        let contentView = MediaViewerInteractiveImageView(frame: contentViewFrame(index: index))
         contentView.imageModel = imageModel
         scrollView.addSubview(contentView)
-
         return contentView
     }
 

        scrollView.showsHorizontalScrollIndicator = false
        addSubview(scrollView)

        scrollView.setFullScreenConstraints()
    }

    private func updateViewWithImages(_ newImages: [MediaViewerImageModel], selectedImage: MediaViewerImageModel) {
        for (index, image) in newImages.enumerated() {
            let contentView = contentViewWithImageModel(image, frame: contentViewFrame(index: index))
            contentViews.append(contentView)
        }


    }

    private func setupScrollView() {
        var frame = bounds
        frame.origin.x -= Constants.leadingMargin
        frame.size.width += Constants.leadingMargin * 2

        scrollView = UIScrollView(frame: frame)
        scrollView.clipsToBounds = false
        scrollView.isUserInteractionEnabled = true
        scrollView.isPagingEnabled = true
