diff --git a/CustomSegues.xcodeproj/project.pbxproj b/CustomSegues.xcodeproj/project.pbxproj index 8681ae1..0397a19 100755 --- a/CustomSegues.xcodeproj/project.pbxproj +++ b/CustomSegues.xcodeproj/project.pbxproj @@ -160,14 +160,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0810; ORGANIZATIONNAME = HoodBrains; TargetAttributes = { 5CC492DF19C7159F001B88BB = { CreatedOnToolsVersion = 6.0; + LastSwiftMigration = 0810; }; 5CC492F419C715A0001B88BB = { CreatedOnToolsVersion = 6.0; + LastSwiftMigration = 0810; TestTargetID = 5CC492DF19C7159F001B88BB; }; }; @@ -273,8 +275,10 @@ 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_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -283,6 +287,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -316,8 +321,10 @@ 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_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -325,6 +332,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -334,6 +342,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -346,6 +355,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.hoodbrains.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -357,6 +367,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.hoodbrains.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -376,6 +387,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.hoodbrains.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CustomSegues.app/CustomSegues"; }; name = Debug; @@ -392,6 +404,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.hoodbrains.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CustomSegues.app/CustomSegues"; }; name = Release; diff --git a/CustomSegues.xcodeproj/project.xcworkspace/xcuserdata/matheusvds.xcuserdatad/UserInterfaceState.xcuserstate b/CustomSegues.xcodeproj/project.xcworkspace/xcuserdata/matheusvds.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..a517464 Binary files /dev/null and b/CustomSegues.xcodeproj/project.xcworkspace/xcuserdata/matheusvds.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/CustomSegues.xcodeproj/xcshareddata/xcschemes/CustomSegues.xcscheme b/CustomSegues.xcodeproj/xcshareddata/xcschemes/CustomSegues.xcscheme index c33f37d..e19ed8a 100644 --- a/CustomSegues.xcodeproj/xcshareddata/xcschemes/CustomSegues.xcscheme +++ b/CustomSegues.xcodeproj/xcshareddata/xcschemes/CustomSegues.xcscheme @@ -1,6 +1,6 @@ + + + + SuppressBuildableAutocreation + + 5CC492DF19C7159F001B88BB + + primary + + + 5CC492F419C715A0001B88BB + + primary + + + + + diff --git a/CustomSegues/AppDelegate.swift b/CustomSegues/AppDelegate.swift index e9fb43f..82df056 100755 --- a/CustomSegues/AppDelegate.swift +++ b/CustomSegues/AppDelegate.swift @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/CustomSegues/Base.lproj/Main.storyboard b/CustomSegues/Base.lproj/Main.storyboard index 09aa9d3..9f497e1 100755 --- a/CustomSegues/Base.lproj/Main.storyboard +++ b/CustomSegues/Base.lproj/Main.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -14,24 +18,24 @@ - + - + @@ -53,25 +57,25 @@ - + - + diff --git a/CustomSegues/CustomSegue.swift b/CustomSegues/CustomSegue.swift index f7b1261..f5c8536 100755 --- a/CustomSegues/CustomSegue.swift +++ b/CustomSegues/CustomSegue.swift @@ -10,218 +10,257 @@ import UIKit import QuartzCore enum CustomSegueAnimation { - case Push - case SwipeDown - case GrowScale - case CornerRotate + case push + case swipeDown + case growScale + case cornerRotate + case fade } // MARK: Segue class class CustomSegue: UIStoryboardSegue { - var animationType = CustomSegueAnimation.Push + var animationType = CustomSegueAnimation.push override func perform() { switch animationType { - case .Push: + case .push: animatePush() - case .SwipeDown: + case .swipeDown: animateSwipeDown() - case .GrowScale: + case .growScale: animateGrowScale() - case .CornerRotate: + case .cornerRotate: animateCornerRotate() + case .fade: + animateFade() } } private func animatePush() { - let toViewController = destinationViewController - let fromViewController = sourceViewController + let toViewController = destination + let fromViewController = source let containerView = fromViewController.view.superview - let screenBounds = UIScreen.mainScreen().bounds + let screenBounds = UIScreen.main.bounds let finalToFrame = screenBounds - let finalFromFrame = CGRectOffset(finalToFrame, -screenBounds.size.width, 0) + let finalFromFrame = finalToFrame.offsetBy(dx: -screenBounds.size.width, dy: 0) - toViewController.view.frame = CGRectOffset(finalToFrame, screenBounds.size.width, 0) + toViewController.view.frame = finalToFrame.offsetBy(dx: screenBounds.size.width, dy: 0) containerView?.addSubview(toViewController.view) - UIView.animateWithDuration(0.5, animations: { + UIView.animate(withDuration: 0.5, animations: { toViewController.view.frame = finalToFrame fromViewController.view.frame = finalFromFrame - }, completion: { finished in - let fromVC = self.sourceViewController - let toVC = self.destinationViewController - fromVC.presentViewController(toVC, animated: false, completion: nil) + }, completion: { finished in + let fromVC = self.source + let toVC = self.destination + fromVC.present(toVC, animated: false, completion: nil) }) } private func animateSwipeDown() { - let toViewController = destinationViewController - let fromViewController = sourceViewController + let toViewController = destination + let fromViewController = source let containerView = fromViewController.view.superview - let screenBounds = UIScreen.mainScreen().bounds + let screenBounds = UIScreen.main.bounds let finalToFrame = screenBounds - let finalFromFrame = CGRectOffset(finalToFrame, 0, screenBounds.size.height) + let finalFromFrame = finalToFrame.offsetBy(dx: 0, dy: screenBounds.size.height) - toViewController.view.frame = CGRectOffset(finalToFrame, 0, -screenBounds.size.height) + toViewController.view.frame = finalToFrame.offsetBy(dx: 0, dy: -screenBounds.size.height) containerView?.addSubview(toViewController.view) - UIView.animateWithDuration(0.5, animations: { + UIView.animate(withDuration: 0.5, animations: { toViewController.view.frame = finalToFrame fromViewController.view.frame = finalFromFrame - }, completion: { finished in - let fromVC = self.sourceViewController - let toVC = self.destinationViewController - fromVC.presentViewController(toVC, animated: false, completion: nil) + }, completion: { finished in + let fromVC = self.source + let toVC = self.destination + fromVC.present(toVC, animated: false, completion: nil) }) } private func animateGrowScale() { - let toViewController = destinationViewController - let fromViewController = sourceViewController + let toViewController = destination + let fromViewController = source let containerView = fromViewController.view.superview let originalCenter = fromViewController.view.center - toViewController.view.transform = CGAffineTransformMakeScale(0.05, 0.05) + toViewController.view.transform = CGAffineTransform(scaleX: 0.05, y: 0.05) toViewController.view.center = originalCenter containerView?.addSubview(toViewController.view) - UIView.animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { - toViewController.view.transform = CGAffineTransformMakeScale(1.0, 1.0) - }, completion: { finished in - let fromVC = self.sourceViewController - let toVC = self.destinationViewController - fromVC.presentViewController(toVC, animated: false, completion: nil) + UIView.animate(withDuration: 0.5, delay: 0.0, options: UIViewAnimationOptions.curveEaseInOut, animations: { + toViewController.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) + }, completion: { finished in + let fromVC = self.source + let toVC = self.destination + fromVC.present(toVC, animated: false, completion: nil) }) } private func animateCornerRotate() { - let toViewController = destinationViewController - let fromViewController = sourceViewController + let toViewController = destination + let fromViewController = source - toViewController.view.layer.anchorPoint = CGPointZero - fromViewController.view.layer.anchorPoint = CGPointZero + toViewController.view.layer.anchorPoint = CGPoint.zero + fromViewController.view.layer.anchorPoint = CGPoint.zero - toViewController.view.layer.position = CGPointZero - fromViewController.view.layer.position = CGPointZero + toViewController.view.layer.position = CGPoint.zero + fromViewController.view.layer.position = CGPoint.zero let containerView: UIView? = fromViewController.view.superview - toViewController.view.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_2)) + toViewController.view.transform = CGAffineTransform(rotationAngle: CGFloat(-M_PI_2)) containerView?.addSubview(toViewController.view) - UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.8, options: UIViewAnimationOptions.TransitionNone, animations: { - fromViewController.view.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2)) - toViewController.view.transform = CGAffineTransformIdentity - }, completion: { finished in - let fromVC: UIViewController = self.sourceViewController - let toVC: UIViewController = self.destinationViewController - fromVC.presentViewController(toVC, animated: false, completion: nil) + UIView.animate(withDuration: 0.5, delay: 1.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.8, options: [], animations: { + fromViewController.view.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI_2)) + toViewController.view.transform = CGAffineTransform.identity + }, completion: { finished in + let fromVC: UIViewController = self.source + let toVC: UIViewController = self.destination + fromVC.present(toVC, animated: false, completion: nil) }) } -} + + private func animateFade() { + let toViewController = destination + let fromViewController = source + + let containerView = fromViewController.view.superview + toViewController.view.alpha = 0 + containerView?.addSubview(toViewController.view) + + UIView.animate(withDuration: 0.5, delay: 0.0, options: UIViewAnimationOptions.curveEaseInOut, animations: { + toViewController.view.alpha = 1 + }, completion: { finished in + let fromVC = self.source + let toVC = self.destination + fromVC.present(toVC, animated: false, completion: nil) + }) + }} // MARK: Unwind Segue class class CustomUnwindSegue: UIStoryboardSegue { - var animationType: CustomSegueAnimation = .Push + var animationType: CustomSegueAnimation = .push override func perform() { switch animationType { - case .Push: + case .push: animatePush() - case .SwipeDown: + case .swipeDown: animateSwipeDown() - case .GrowScale: + case .growScale: animateGrowScale() - case .CornerRotate: + case .cornerRotate: animateCornerRotate() + case .fade: + animateFade() } } private func animatePush() { - let toViewController = destinationViewController - let fromViewController = sourceViewController + let toViewController = destination + let fromViewController = source let containerView = fromViewController.view.superview - let screenBounds = UIScreen.mainScreen().bounds + let screenBounds = UIScreen.main.bounds let finalToFrame = screenBounds - let finalFromFrame = CGRectOffset(finalToFrame, screenBounds.size.width, 0) + let finalFromFrame = finalToFrame.offsetBy(dx: screenBounds.size.width, dy: 0) - toViewController.view.frame = CGRectOffset(finalToFrame, -screenBounds.size.width, 0) + toViewController.view.frame = finalToFrame.offsetBy(dx: -screenBounds.size.width, dy: 0) containerView?.addSubview(toViewController.view) - UIView.animateWithDuration(0.5, animations: { + UIView.animate(withDuration: 0.5, animations: { toViewController.view.frame = finalToFrame fromViewController.view.frame = finalFromFrame - }, completion: { finished in - let fromVC: UIViewController = self.sourceViewController - fromVC.dismissViewControllerAnimated(false, completion: nil) + }, completion: { finished in + let fromVC: UIViewController = self.source + fromVC.dismiss(animated: false, completion: nil) }) } private func animateSwipeDown() { - let toViewController = destinationViewController - let fromViewController = sourceViewController + let toViewController = destination + let fromViewController = source let containerView = fromViewController.view.superview - let screenBounds = UIScreen.mainScreen().bounds + let screenBounds = UIScreen.main.bounds let finalToFrame = screenBounds - let finalFromFrame = CGRectOffset(finalToFrame, 0, -screenBounds.size.height) + let finalFromFrame = finalToFrame.offsetBy(dx: 0, dy: -screenBounds.size.height) - toViewController.view.frame = CGRectOffset(finalToFrame, 0, screenBounds.size.height) + toViewController.view.frame = finalToFrame.offsetBy(dx: 0, dy: screenBounds.size.height) containerView?.addSubview(toViewController.view) - UIView.animateWithDuration(0.5, animations: { + UIView.animate(withDuration: 0.5, animations: { toViewController.view.frame = finalToFrame fromViewController.view.frame = finalFromFrame - }, completion: { finished in - let fromVC: UIViewController = self.sourceViewController - fromVC.dismissViewControllerAnimated(false, completion: nil) + }, completion: { finished in + let fromVC: UIViewController = self.source + fromVC.dismiss(animated: false, completion: nil) }) } private func animateGrowScale() { - let toViewController = destinationViewController - let fromViewController = sourceViewController + let toViewController = destination + let fromViewController = source - fromViewController.view.superview?.insertSubview(toViewController.view, atIndex: 0) + fromViewController.view.superview?.insertSubview(toViewController.view, at: 0) - UIView.animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { - fromViewController.view.transform = CGAffineTransformMakeScale(0.05, 0.05) - }, completion: { finished in - let fromVC = self.sourceViewController - fromVC.dismissViewControllerAnimated(false, completion: nil) + UIView.animate(withDuration: 0.5, delay: 0.0, options: UIViewAnimationOptions.curveEaseInOut, animations: { + fromViewController.view.transform = CGAffineTransform(scaleX: 0.05, y: 0.05) + }, completion: { finished in + let fromVC = self.source + fromVC.dismiss(animated: false, completion: nil) }) } private func animateCornerRotate() { - let toViewController = destinationViewController - let fromViewController = sourceViewController + let toViewController = destination + let fromViewController = source - toViewController.view.layer.anchorPoint = CGPointZero - fromViewController.view.layer.anchorPoint = CGPointZero + toViewController.view.layer.anchorPoint = CGPoint.zero + fromViewController.view.layer.anchorPoint = CGPoint.zero - toViewController.view.layer.position = CGPointZero - fromViewController.view.layer.position = CGPointZero + toViewController.view.layer.position = CGPoint.zero + fromViewController.view.layer.position = CGPoint.zero let containerView = fromViewController.view.superview containerView?.addSubview(toViewController.view) - UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.8, options: UIViewAnimationOptions.TransitionNone, animations: { - fromViewController.view.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_2)) - toViewController.view.transform = CGAffineTransformIdentity - }, completion: { finished in - let fromVC = self.sourceViewController - fromVC.dismissViewControllerAnimated(false, completion: nil) + UIView.animate(withDuration: 0.5, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.8, options: [], animations: { + fromViewController.view.transform = CGAffineTransform(rotationAngle: CGFloat(-M_PI_2)) + toViewController.view.transform = CGAffineTransform.identity + }, completion: { finished in + let fromVC = self.source + fromVC.dismiss(animated: false, completion: nil) }) - + } -} \ No newline at end of file + + private func animateFade() { + let toViewController = destination + let fromViewController = source + + let containerView = fromViewController.view.superview + toViewController.view.alpha = 1 + containerView?.addSubview(toViewController.view) + + UIView.animate(withDuration: 0.5, delay: 0.0, options: UIViewAnimationOptions.curveEaseInOut, animations: { + toViewController.view.alpha = 0 + }, completion: { finished in + let fromVC = self.source + let toVC = self.destination + fromVC.present(toVC, animated: false, completion: nil) + }) + } +} + diff --git a/CustomSegues/FirstViewController.swift b/CustomSegues/FirstViewController.swift index 9c38f8e..48e1fc3 100755 --- a/CustomSegues/FirstViewController.swift +++ b/CustomSegues/FirstViewController.swift @@ -10,23 +10,23 @@ import UIKit class FirstViewController: UIViewController { - override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue is CustomSegue { - (segue as! CustomSegue).animationType = .Push + (segue as! CustomSegue).animationType = .push } } @IBAction func go() { - performSegueWithIdentifier("CustomSegue", sender: nil) + performSegue(withIdentifier: "CustomSegue", sender: nil) } - @IBAction func unwindFromViewController(sender: UIStoryboardSegue) { + @IBAction func unwindFromViewController(_ sender: UIStoryboardSegue) { } - override func segueForUnwindingToViewController(toViewController: UIViewController, fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue { + override func segueForUnwinding(to toViewController: UIViewController, from fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue { let segue = CustomUnwindSegue(identifier: identifier, source: fromViewController, destination: toViewController) - segue.animationType = .Push + segue.animationType = .push return segue } -} \ No newline at end of file +} diff --git a/CustomSeguesTests/CustomSeguesTests.swift b/CustomSeguesTests/CustomSeguesTests.swift index 7cf7870..c1f8077 100755 --- a/CustomSeguesTests/CustomSeguesTests.swift +++ b/CustomSeguesTests/CustomSeguesTests.swift @@ -28,7 +28,7 @@ class CustomSeguesTests: XCTestCase { func testPerformanceExample() { // This is an example of a performance test case. - self.measureBlock() { + self.measure() { // Put the code you want to measure the time of here. } }