From cc9f258be075d69a0297bbe464aefeae17c2fecc Mon Sep 17 00:00:00 2001 From: Rico Becker Date: Fri, 5 Oct 2018 17:53:58 +0200 Subject: [PATCH 1/4] Updates Swift version to 4.2 --- MKCubeController.xcodeproj/project.pbxproj | 11 ++++++++--- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ MKCubeController/MKCubeViewController.swift | 12 ++++++------ .../MKCubeControllerDemo.xcodeproj/project.pbxproj | 11 ++++++++--- .../MKCubeControllerDemo/AppDelegate.swift | 2 +- 5 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 MKCubeController.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist 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..74f6035 100644 --- a/MKCubeController/MKCubeViewController.swift +++ b/MKCubeController/MKCubeViewController.swift @@ -110,19 +110,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 +175,7 @@ public class MKCubeViewController: UIViewController, UIScrollViewDelegate { controller.viewWillDisappear(false) controller.view!.removeFromSuperview() - controller.removeFromParentViewController() + controller.removeFromParent() controller.viewDidDisappear(false) } @@ -219,7 +219,7 @@ public class MKCubeViewController: UIViewController, UIScrollViewDelegate { controller.view.autoresizingMask = [] controller.view.layer.isDoubleSided = false - addChildViewController(controller) + addChild(controller) scrollView.addSubview(controller.view) } @@ -292,7 +292,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..4ebe8e8 100644 --- a/MKCubeControllerDemo/MKCubeControllerDemo/AppDelegate.swift +++ b/MKCubeControllerDemo/MKCubeControllerDemo/AppDelegate.swift @@ -14,7 +14,7 @@ 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.dataSource = self From 3454ac91a49b6e3849a9b236443734e50e45ff96 Mon Sep 17 00:00:00 2001 From: Rico Becker Date: Fri, 5 Oct 2018 17:58:03 +0200 Subject: [PATCH 2/4] Adds public focal length property --- MKCubeController/MKCubeViewController.swift | 4 +++- MKCubeControllerDemo/MKCubeControllerDemo/AppDelegate.swift | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/MKCubeController/MKCubeViewController.swift b/MKCubeController/MKCubeViewController.swift index 74f6035..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 @@ -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) diff --git a/MKCubeControllerDemo/MKCubeControllerDemo/AppDelegate.swift b/MKCubeControllerDemo/MKCubeControllerDemo/AppDelegate.swift index 4ebe8e8..a5f8ed9 100644 --- a/MKCubeControllerDemo/MKCubeControllerDemo/AppDelegate.swift +++ b/MKCubeControllerDemo/MKCubeControllerDemo/AppDelegate.swift @@ -17,6 +17,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MKCubeViewControllerDataS func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let controller = MKCubeViewController() + controller.focalLength = 1000 controller.dataSource = self controller.wrapEnabled = true From 997a4fb6e77858c07734af4ac57b04dc8744ab15 Mon Sep 17 00:00:00 2001 From: Rico Becker Date: Fri, 5 Oct 2018 18:20:01 +0200 Subject: [PATCH 3/4] Adds AutoLayout to example view controller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Demo didn’t work on iPhones with SafeArea Insets --- .../BlueViewController.xib | 61 ++++++++++------- .../GreenViewController.xib | 67 +++++++++++-------- .../RedViewController.xib | 67 +++++++++++-------- 3 files changed, 118 insertions(+), 77 deletions(-) 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 + From 7c3be343c94516d4cbef9ed3ba91602e7aacaeeb Mon Sep 17 00:00:00 2001 From: Rico Becker Date: Fri, 5 Oct 2018 18:42:38 +0200 Subject: [PATCH 4/4] Update README.md --- README.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) 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.