Skip to content
This repository was archived by the owner on Jul 3, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Examples/MonoImage/Sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class ViewController: UIViewController {
#else
let panoramaView = PanoramaView(frame: view.bounds) // iOS Simulator
#endif
panoramaView.setNeedsResetRotation()
panoramaView.moveType = .all
panoramaView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(panoramaView)

Expand All @@ -40,7 +40,7 @@ final class ViewController: UIViewController {
NSLayoutConstraint.activate(constraints)

// double tap to reset rotation
let doubleTapGestureRecognizer = UITapGestureRecognizer(target: panoramaView, action: #selector(PanoramaView.setNeedsResetRotation(_:)))
let doubleTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(changeMode))
doubleTapGestureRecognizer.numberOfTapsRequired = 2
panoramaView.addGestureRecognizer(doubleTapGestureRecognizer)

Expand All @@ -49,6 +49,16 @@ final class ViewController: UIViewController {
panoramaView.load(#imageLiteral(resourceName: "Sample"), format: .mono)
}

func changeMode() {
if self.panoramaView?.moveType == .all {
self.panoramaView?.moveType = .touch
} else if self.panoramaView?.moveType == .touch {
self.panoramaView?.moveType = .motion
} else {
self.panoramaView?.moveType = .all
}
}

override func viewDidLoad() {
super.viewDidLoad()

Expand Down
4 changes: 4 additions & 0 deletions MetalScope.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
46ADA8B11F7A421F00258B43 /* MoveType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46ADA8B01F7A421F00258B43 /* MoveType.swift */; };
BF1452DF1E320BAC0042598E /* SceneLoadable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF1452DE1E320BAC0042598E /* SceneLoadable.swift */; };
BF1453061E321CE30042598E /* CategoryBitMask.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF1453051E321CE30042598E /* CategoryBitMask.swift */; };
BF1F1D381EAF6A53004AEEB4 /* PanoramaPanGestureManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFB8922F1E2F761600FA9129 /* PanoramaPanGestureManager.swift */; };
Expand Down Expand Up @@ -47,6 +48,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
46ADA8B01F7A421F00258B43 /* MoveType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveType.swift; sourceTree = "<group>"; };
BF1452DE1E320BAC0042598E /* SceneLoadable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = SceneLoadable.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
BF1453051E321CE30042598E /* CategoryBitMask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = CategoryBitMask.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
BF46F0991EADDEDA00F5CB58 /* Deprecations+Removals.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deprecations+Removals.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -216,6 +218,7 @@
children = (
BFB8919E1E2E083000FA9129 /* PanoramaView.swift */,
BFB8922F1E2F761600FA9129 /* PanoramaPanGestureManager.swift */,
46ADA8B01F7A421F00258B43 /* MoveType.swift */,
);
name = PanoramaView;
sourceTree = "<group>";
Expand Down Expand Up @@ -335,6 +338,7 @@
BFB891A81E2E10CA00FA9129 /* Rotation+SceneKit.swift in Sources */,
BF603F551E41B57600A28013 /* OrientationIndicator.swift in Sources */,
BF1F1D381EAF6A53004AEEB4 /* PanoramaPanGestureManager.swift in Sources */,
46ADA8B11F7A421F00258B43 /* MoveType.swift in Sources */,
BFB8920B1E2F364B00FA9129 /* SphericalMediaScene.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Deprecations+Removals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension OrientationNode {

@available(*, renamed: "OrientationNode.resetRotation")
public func resetCenter(animated: Bool, completionHanlder: (() -> Void)? = nil) {
resetRotation(animated: animated, completionHanlder: completionHanlder)
resetRotation(animated: animated, fully: false, completionHanlder: completionHanlder)
}
}

Expand Down
13 changes: 13 additions & 0 deletions Sources/MoveType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// MoveType.swift
// MetalScope
//
// Created by Иван Морозов on 9/26/17.
// Copyright © 2017 MintRocket LLC. All rights reserved.
//

public enum PanoramaMoveType {
case all
case motion
case touch
}
33 changes: 28 additions & 5 deletions Sources/OrientationNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@ public final class OrientationNode: SCNNode {
}
}

public var deviceOrientationProvider: DeviceOrientationProvider? = DefaultDeviceOrientationProvider()
public var motionIsEnabled = true

private var provider: DeviceOrientationProvider? = DefaultDeviceOrientationProvider()
public var deviceOrientationProvider: DeviceOrientationProvider? {
get {
if motionIsEnabled {
return provider
}
return nil
}
set {
provider = newValue
}
}

public var interfaceOrientationProvider: InterfaceOrientationProvider? = DefaultInterfaceOrientationProvider()

Expand Down Expand Up @@ -96,15 +109,25 @@ public final class OrientationNode: SCNNode {
userRotationNode.transform = SCNMatrix4Identity
}

public func resetRotation(animated: Bool, completionHanlder: (() -> Void)? = nil) {
public func fullyResetRotation() {
userRotationNode.transform = SCNMatrix4Identity
referenceRotationNode.transform = SCNMatrix4Identity
deviceOrientationNode.transform = SCNMatrix4Identity
}

public func resetRotation(animated: Bool, fully: Bool, completionHanlder: (() -> Void)? = nil) {
SCNTransaction.lock()
SCNTransaction.begin()
SCNTransaction.animationDuration = 0.6
SCNTransaction.animationTimingFunction = CAMediaTimingFunction(controlPoints: 0.2, 0, 0, 1)
SCNTransaction.completionBlock = completionHanlder
SCNTransaction.disableActions = !animated

resetRotation()
if fully {
fullyResetRotation()
} else {
resetRotation()
}

SCNTransaction.commit()
SCNTransaction.unlock()
Expand All @@ -113,9 +136,9 @@ public final class OrientationNode: SCNNode {
/// Requests reset of rotation in the next rendering frame.
///
/// - Parameter animated: Pass true to animate the transition.
public func setNeedsResetRotation(animated: Bool) {
public func setNeedsResetRotation(animated: Bool, fully: Bool) {
let action = SCNAction.run { node in
(node as! OrientationNode).resetRotation(animated: animated)
(node as! OrientationNode).resetRotation(animated: animated, fully: fully)
}
runAction(action, forKey: "setNeedsResetRotation")
}
Expand Down
16 changes: 14 additions & 2 deletions Sources/PanoramaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public final class PanoramaView: UIView, SceneLoadable {
public let device: MTLDevice
#endif

public var moveType: PanoramaMoveType = .all {
didSet {
updateMoveType()
}
}

public var scene: SCNScene? {
get {
return scnView.scene
Expand Down Expand Up @@ -98,6 +104,12 @@ public final class PanoramaView: UIView, SceneLoadable {
interfaceOrientationUpdater.updateInterfaceOrientation()
}
}

fileprivate func updateMoveType() {
self.panGestureManager.gestureRecognizer.isEnabled = [.all, .touch].contains(self.moveType)
self.orientationNode.motionIsEnabled = [.all, .motion].contains(self.moveType)
self.setNeedsResetRotation(animated: true, fully: true)
}
}

extension PanoramaView: ImageLoadable {}
Expand Down Expand Up @@ -145,9 +157,9 @@ extension PanoramaView {
interfaceOrientationUpdater.updateInterfaceOrientation(with: transitionCoordinator)
}

public func setNeedsResetRotation(animated: Bool = false) {
public func setNeedsResetRotation(animated: Bool = false, fully: Bool = false) {
panGestureManager.stopAnimations()
orientationNode.setNeedsResetRotation(animated: animated)
orientationNode.setNeedsResetRotation(animated: animated, fully: fully)
}

public func setNeedsResetRotation(_ sender: Any?) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/StereoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ extension StereoView {
}

public func setNeedsResetRotation() {
orientationNode.setNeedsResetRotation(animated: false)
orientationNode.setNeedsResetRotation(animated: false, fully: false)
}
}

Expand Down