diff --git a/MKCubeController.xcodeproj/project.pbxproj b/MKCubeController.xcodeproj/project.pbxproj index 5959b27..67fd172 100644 --- a/MKCubeController.xcodeproj/project.pbxproj +++ b/MKCubeController.xcodeproj/project.pbxproj @@ -96,11 +96,12 @@ 49BBCFE01C598D650052F869 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0920; + LastUpgradeCheck = 1010; ORGANIZATIONNAME = "Kevin Malkic"; TargetAttributes = { 49BBCFE81C598D650052F869 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 1010; }; }; }; @@ -156,12 +157,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -212,12 +215,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -269,7 +274,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -291,7 +296,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.kevinmalkic.MKCubeController; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/MKCubeController.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/MKCubeController.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/MKCubeController.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/MKCubeController/MKCubeViewController.swift b/MKCubeController/MKCubeViewController.swift index cf50891..a8d5814 100644 --- a/MKCubeController/MKCubeViewController.swift +++ b/MKCubeController/MKCubeViewController.swift @@ -31,6 +31,8 @@ public class MKCubeViewController: UIViewController, UIScrollViewDelegate { public weak var dataSource: MKCubeViewControllerDataSource? public weak var delegate: MKCubeViewControllerDelegate? + public var focalLength: CGFloat = 500 + private var controllers = [Int: UIViewController]() private var scrollOffset: CGFloat = 0 private var previousOffset: CGFloat = 0 @@ -110,19 +112,19 @@ public class MKCubeViewController: UIViewController, UIScrollViewDelegate { if animated { let animation: CATransition = CATransition() - animation.type = kCATransitionFade + animation.type = CATransitionType.fade scrollView.layer.add(animation, forKey: nil) } controller.view!.removeFromSuperview() - controller.removeFromParentViewController() + controller.removeFromParent() if let newController = dataSource?.cubeController(cubeController: self, viewControllerAtIndex: index) { controllers[index] = newController newController.view.layer.isDoubleSided = false - addChildViewController(newController) + addChild(newController) scrollView.addSubview(newController.view!) newController.view.layer.transform = transform @@ -175,7 +177,7 @@ public class MKCubeViewController: UIViewController, UIScrollViewDelegate { controller.viewWillDisappear(false) controller.view!.removeFromSuperview() - controller.removeFromParentViewController() + controller.removeFromParent() controller.viewDidDisappear(false) } @@ -219,7 +221,7 @@ public class MKCubeViewController: UIViewController, UIScrollViewDelegate { controller.view.autoresizingMask = [] controller.view.layer.isDoubleSided = false - addChildViewController(controller) + addChild(controller) scrollView.addSubview(controller.view) } @@ -238,7 +240,7 @@ public class MKCubeViewController: UIViewController, UIScrollViewDelegate { if angle != 0.0 { - transform.m34 = -1.0 / 500 + transform.m34 = 1.0 / -focalLength transform = CATransform3DTranslate(transform, 0, 0, -view.bounds.size.width / 2.0) transform = CATransform3DRotate(transform, -CGFloat(angle), 0, 1, 0) transform = CATransform3DTranslate(transform, 0, 0, view.bounds.size.width / 2.0) @@ -292,7 +294,7 @@ public class MKCubeViewController: UIViewController, UIScrollViewDelegate { if !visibleIndices.contains(index) { controller.view!.removeFromSuperview() - controller.removeFromParentViewController() + controller.removeFromParent() controllers.removeValue(forKey: index) } } diff --git a/MKCubeControllerDemo/MKCubeControllerDemo.xcodeproj/project.pbxproj b/MKCubeControllerDemo/MKCubeControllerDemo.xcodeproj/project.pbxproj index 689dd7d..5fae3b5 100644 --- a/MKCubeControllerDemo/MKCubeControllerDemo.xcodeproj/project.pbxproj +++ b/MKCubeControllerDemo/MKCubeControllerDemo.xcodeproj/project.pbxproj @@ -117,11 +117,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0920; + LastUpgradeCheck = 1010; ORGANIZATIONNAME = "Kevin Malkic"; TargetAttributes = { 0A95A5041C5A342D00430543 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 1010; }; }; }; @@ -194,12 +195,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -247,12 +250,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -292,7 +297,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.ustwo.MKCubeControllerDemo; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -306,7 +311,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.ustwo.MKCubeControllerDemo; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/MKCubeControllerDemo/MKCubeControllerDemo/AppDelegate.swift b/MKCubeControllerDemo/MKCubeControllerDemo/AppDelegate.swift index ac6d917..a5f8ed9 100644 --- a/MKCubeControllerDemo/MKCubeControllerDemo/AppDelegate.swift +++ b/MKCubeControllerDemo/MKCubeControllerDemo/AppDelegate.swift @@ -14,9 +14,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MKCubeViewControllerDataS var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let controller = MKCubeViewController() + controller.focalLength = 1000 controller.dataSource = self controller.wrapEnabled = true diff --git a/MKCubeControllerDemo/MKCubeControllerDemo/BlueViewController.xib b/MKCubeControllerDemo/MKCubeControllerDemo/BlueViewController.xib index 6bed303..182d714 100644 --- a/MKCubeControllerDemo/MKCubeControllerDemo/BlueViewController.xib +++ b/MKCubeControllerDemo/MKCubeControllerDemo/BlueViewController.xib @@ -1,8 +1,13 @@ - - + + + + + - + + + @@ -12,49 +17,59 @@ - + - - + + + + + + + + + + + + diff --git a/MKCubeControllerDemo/MKCubeControllerDemo/GreenViewController.xib b/MKCubeControllerDemo/MKCubeControllerDemo/GreenViewController.xib index 82c2b1b..996418f 100644 --- a/MKCubeControllerDemo/MKCubeControllerDemo/GreenViewController.xib +++ b/MKCubeControllerDemo/MKCubeControllerDemo/GreenViewController.xib @@ -1,8 +1,13 @@ - - + + + + + - - + + + + @@ -12,51 +17,59 @@ - + - - - - + + + + + + + + + + + + - \ No newline at end of file + diff --git a/MKCubeControllerDemo/MKCubeControllerDemo/RedViewController.xib b/MKCubeControllerDemo/MKCubeControllerDemo/RedViewController.xib index d3e2ffd..f34194e 100644 --- a/MKCubeControllerDemo/MKCubeControllerDemo/RedViewController.xib +++ b/MKCubeControllerDemo/MKCubeControllerDemo/RedViewController.xib @@ -1,8 +1,13 @@ - - + + + + + - - + + + + @@ -12,51 +17,59 @@ - + - - - - + + + + + + + + + + + + - \ No newline at end of file + diff --git a/README.md b/README.md index 7a356a4..a3a138e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MKCubeController -MKCubeController is used to create a rotating 3D cube navigation in Swift 2.1. (translated from @nicklockwood CubeController) +MKCubeController is used to create a rotating 3D cube navigation in Swift 4.2. (translated from @nicklockwood CubeController) here the link https://github.com/nicklockwood/CubeController Pretty much the same logic. @@ -20,28 +20,21 @@ controller.wrapEnabled = true And implement MKCubeViewControllerDataSource ```swift func numberOfViewControllersInCubeController(cubeController: MKCubeViewController) -> Int { - return 3 } func cubeController(cubeController: MKCubeViewController, viewControllerAtIndex index: Int) -> UIViewController { switch index % 3 { - case 0: return ViewController(nibName: "RedViewController", bundle: nil) - case 1: return ViewController(nibName: "GreenViewController", bundle: nil) - case 2: return ViewController(nibName: "BlueViewController", bundle: nil) - default: break - } - return ViewController() } ``` @@ -114,4 +107,4 @@ Kevin Malkic ## License -MKCubeController is released under the MIT license. See LICENSE for details. \ No newline at end of file +MKCubeController is released under the MIT license. See LICENSE for details.