 	
 	// MARK: - Handles Orientation
 	
-	public func setupMotionManager() {
-		self.motionManager.accelerometerUpdateInterval = 0.2
-		self.motionManager.gyroUpdateInterval = 0.2
-	}
-	
-	public func outputAccelertionData(acceleration: CMAcceleration) {
-		var currentOrientation: UIInterfaceOrientation?
-		
-		if acceleration.x >= 0.75 {
-			currentOrientation = .LandscapeLeft
-		} else if acceleration.x <= -0.75 {
-			currentOrientation = .LandscapeRight
-		} else if acceleration.y <= -0.75 {
-			currentOrientation = .Portrait
-		} else if acceleration.y >= 0.75 {
-			currentOrientation = .PortraitUpsideDown
-		} else {
-			return
-		}
-		
-		if self.currentOrientation != currentOrientation! {
-			self.currentOrientation = currentOrientation!
-			
-			self.updateUIForCurrentOrientation()
-		}
-	}
-	
-	public func updateUIForCurrentOrientation() {
-		var degree = 0.0
-		
-		switch self.currentOrientation {
-		case .Portrait:
-			degree = 0
-		case .PortraitUpsideDown:
-			degree = 180
-		case .LandscapeLeft:
-			degree = 270
-		case .LandscapeRight:
-			degree = 90
-		default:
-			degree = 0.0
-		}
-		
-		let rotateAffineTransform = CGAffineTransformRotate(CGAffineTransformIdentity, degreesToRadians(degree))
-		
-		UIView.animateWithDuration(0.2) { () -> Void in
-			self.flashButton.transform = rotateAffineTransform
-			self.cameraSwitchButton.transform = rotateAffineTransform
-		}
-	}
-	
 	public override func shouldAutorotate() -> Bool {
 		return false
 	}
 	
-	public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
-		return UIInterfaceOrientationMask.Portrait
-	}
-	
+	public func setupMotionManager() {
+		self.motionManager.accelerometerUpdateInterval = 0.5
+		self.motionManager.gyroUpdateInterval = 0.5
+	}
+	
+	public func updateLayoutForCurrentOrientation() {
+		var contentViewNewSize: CGSize!
+		let width = self.view.bounds.width
+		let height = self.view.bounds.height
+		if UIDeviceOrientationIsLandscape(self.currentOrientation) {
+			contentViewNewSize = CGSize(width: max(width, height), height: min(width, height))
+		} else {
+			contentViewNewSize = CGSize(width: min(width, height), height: max(width, height))
+		}
+		
+		let newAngle = self.currentOrientation.toAngleRelativeToPortrait() - self.originalOrientation.toAngleRelativeToPortrait()
+		
+		UIView.animateWithDuration(0.25) {
+			self.contentView.bounds.size = contentViewNewSize
+			self.contentView.transform = CGAffineTransformMakeRotation(newAngle)
+		}
+	}
+
 }
 
 // MARK: - Utilities
 
-public extension UIInterfaceOrientation {
+public extension UIDeviceOrientation {
 	
 	func toAVCaptureVideoOrientation() -> AVCaptureVideoOrientation {
-		return AVCaptureVideoOrientation(rawValue: self.rawValue)!
+		switch self {
+		case .Portrait:
+			return .Portrait
+		case .PortraitUpsideDown:
+			return .PortraitUpsideDown
+		case .LandscapeRight:
+			return .LandscapeLeft
+		case .LandscapeLeft:
+			return .LandscapeRight
+		default:
+			return .Portrait
+		}
+	}
+	
+	func toAngleRelativeToPortrait() -> CGFloat {
+		switch self {
+		case .Portrait:
+			return 0
+		case .PortraitUpsideDown:
+			return CGFloat(M_PI)
+		case .LandscapeRight:
+			return CGFloat(-M_PI_2)
+		case .LandscapeLeft:
+			return CGFloat(M_PI_2)
+		default:
+			return 0
+		}
 	}
 	
 }
 
-public func degreesToRadians(degree: Double) -> CGFloat {
-	return CGFloat(degree / 180.0 * M_PI)
+public extension CMAcceleration {
+	func toDeviceOrientation() -> UIDeviceOrientation? {
+		if self.x >= 0.75 {
+			return .LandscapeRight
+		} else if self.x <= -0.75 {
+			return .LandscapeLeft
+		} else if self.y <= -0.75 {
+			return .Portrait
+		} else if self.y >= 0.75 {
+			return .PortraitUpsideDown
+		} else {
+			return nil
+		}
+	}
 }
 
 // MARK: - Rersources

			self.zoomScale = min(4.0, max(1.0, self.beginZoomScale * gesture.scale))
			CATransaction.begin()
			CATransaction.setAnimationDuration(0.025)
			self.previewLayer?.setAffineTransform(CGAffineTransformMakeScale(self.zoomScale, self.zoomScale))
			CATransaction.commit()
		}
	}

		}
		
		if !self.motionManager.accelerometerActive {
			self.motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.currentQueue()!, withHandler: { accelerometerData, error in
				if error == nil {
					let currentOrientation = accelerometerData!.acceleration.toDeviceOrientation() ?? self.currentOrientation
					if self.currentOrientation != currentOrientation {
						self.currentOrientation = currentOrientation
						self.updateLayoutForCurrentOrientation()
					}
				} else {
					print("error while update accelerometer: \(error!.localizedDescription)", terminator: "")
				}
