 		}
 		
 		dismissCompletion?(completed)
+	}
+	
+	// MARK:- Presented view KVO
+	
+	override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
+		if keyPath == "transform" || keyPath == "frame", let view = object as? UIView {
+			let offset = view.frame.origin.y
+			updateRoundedMask(forOffset: offset)
+		}
+	}
+	
+	private func updateRoundedMask(forOffset offset: CGFloat) {
+		guard let roundedView = roundedView, let maskLayer = maskLayer else {
+			return
+		}
+		
+		roundedView.frame = CGRect(x: 0, y: offset, width: containerView!.bounds.width, height: 8)
+		maskLayer.frame = roundedView.bounds
+		
+		let radii = CGSize(width: roundedView.bounds.height, height: roundedView.bounds.height)
+		let boundsPath = UIBezierPath(rect: roundedView.bounds)
+		boundsPath.append(UIBezierPath(roundedRect: roundedView.bounds,
+		                               byRoundingCorners: [.topLeft, .topRight],
+		                               cornerRadii: radii))
+		
+		maskLayer.path = boundsPath.cgPath
 	}
 	
 	// MARK:- Gesture handling

		presentingViewController.view.transform = CGAffineTransform(scaleX: scale, y: scale)
		presentingViewSnapshotView?.alpha = 0
		backgroundView?.alpha = 0
	}
	
	/// Method to ensure the layout is as required at the end of the dismissal.

		}
		
        if completed {
			roundedView = UIView()
			roundedView!.backgroundColor = .black
			roundedView!.translatesAutoresizingMaskIntoConstraints = false
			containerView.addSubview(roundedView!)
			
			maskLayer = CAShapeLayer()
			maskLayer!.fillColor = UIColor.black.cgColor
			maskLayer!.fillRule = kCAFillRuleEvenOdd
			roundedView!.layer.mask = maskLayer
			
			presentedViewController.view.addObserver(self, forKeyPath: "frame", options: [.initial], context: nil)
			presentedViewController.view.addObserver(self, forKeyPath: "transform", options: [.initial], context: nil)
			presentedViewController.view.layer.mask = nil
            presentedViewController.view.frame = frameOfPresentedViewInContainerView
			presentAnimation?()
			
			presentingViewSnapshotView = UIView()
