From 976aef7b8ebf99ff48475d4eca3a8ffb81c376c5 Mon Sep 17 00:00:00 2001 From: Alex K Date: Mon, 17 Sep 2018 09:37:36 +0300 Subject: [PATCH] convert to swift 4.2 --- .../BounceAnimation/RAMBounceAnimation.swift | 6 +-- .../RAMFrameItemAnimation.swift | 4 +- .../FumeAnimation/RAMFumeAnimation.swift | 12 +++--- .../RAMRotationAnimation.swift | 4 +- .../RAMTransitionItemAnimations.swift | 16 ++++---- .../RAMAnimatedTabBarController.swift | 40 +++++++++---------- .../RAMBadge/RAMBadge.swift | 24 +++++------ .../project.pbxproj | 19 +++++---- .../RAMAnimatedTabBarDemo/AppDelegate.swift | 2 +- 9 files changed, 63 insertions(+), 64 deletions(-) diff --git a/RAMAnimatedTabBarController/Animations/BounceAnimation/RAMBounceAnimation.swift b/RAMAnimatedTabBarController/Animations/BounceAnimation/RAMBounceAnimation.swift index 7b4296ce..9a1c233b 100755 --- a/RAMAnimatedTabBarController/Animations/BounceAnimation/RAMBounceAnimation.swift +++ b/RAMAnimatedTabBarController/Animations/BounceAnimation/RAMBounceAnimation.swift @@ -48,8 +48,8 @@ open class RAMBounceAnimation: RAMItemAnimation { textLabel.textColor = defaultTextColor if let iconImage = icon.image { - let renderMode = defaultIconColor.cgColor.alpha == 0 ? UIImageRenderingMode.alwaysOriginal : - UIImageRenderingMode.alwaysTemplate + let renderMode = defaultIconColor.cgColor.alpha == 0 ? UIImage.RenderingMode.alwaysOriginal : + UIImage.RenderingMode.alwaysTemplate let renderImage = iconImage.withRenderingMode(renderMode) icon.image = renderImage icon.tintColor = defaultIconColor @@ -77,7 +77,7 @@ open class RAMBounceAnimation: RAMItemAnimation { let bounceAnimation = CAKeyframeAnimation(keyPath: Constants.AnimationKeys.Scale) bounceAnimation.values = [1.0, 1.4, 0.9, 1.15, 0.95, 1.02, 1.0] bounceAnimation.duration = TimeInterval(duration) - bounceAnimation.calculationMode = kCAAnimationCubic + bounceAnimation.calculationMode = CAAnimationCalculationMode.cubic icon.layer.add(bounceAnimation, forKey: nil) diff --git a/RAMAnimatedTabBarController/Animations/FrameAnimation/RAMFrameItemAnimation.swift b/RAMAnimatedTabBarController/Animations/FrameAnimation/RAMFrameItemAnimation.swift index d84208bb..cc39c60d 100644 --- a/RAMAnimatedTabBarController/Animations/FrameAnimation/RAMFrameItemAnimation.swift +++ b/RAMAnimatedTabBarController/Animations/FrameAnimation/RAMFrameItemAnimation.swift @@ -121,12 +121,12 @@ open class RAMFrameItemAnimation: RAMItemAnimation { @nonobjc func playFrameAnimation(_ icon: UIImageView, images: Array) { let frameAnimation = CAKeyframeAnimation(keyPath: Constants.AnimationKeys.KeyFrame) - frameAnimation.calculationMode = kCAAnimationDiscrete + frameAnimation.calculationMode = CAAnimationCalculationMode.discrete frameAnimation.duration = TimeInterval(duration) frameAnimation.values = images frameAnimation.repeatCount = 1 frameAnimation.isRemovedOnCompletion = false - frameAnimation.fillMode = kCAFillModeForwards + frameAnimation.fillMode = CAMediaTimingFillMode.forwards icon.layer.add(frameAnimation, forKey: nil) } } diff --git a/RAMAnimatedTabBarController/Animations/FumeAnimation/RAMFumeAnimation.swift b/RAMAnimatedTabBarController/Animations/FumeAnimation/RAMFumeAnimation.swift index 74f9d90b..8eea8b3e 100755 --- a/RAMAnimatedTabBarController/Animations/FumeAnimation/RAMFumeAnimation.swift +++ b/RAMAnimatedTabBarController/Animations/FumeAnimation/RAMFumeAnimation.swift @@ -59,8 +59,8 @@ open class RAMFumeAnimation: RAMItemAnimation { textLabel.textColor = defaultTextColor if let iconImage = icon.image { - let renderMode = defaultIconColor.cgColor.alpha == 0 ? UIImageRenderingMode.alwaysOriginal : - UIImageRenderingMode.alwaysTemplate + let renderMode = defaultIconColor.cgColor.alpha == 0 ? UIImage.RenderingMode.alwaysOriginal : + UIImage.RenderingMode.alwaysTemplate let renderImage = iconImage.withRenderingMode(renderMode) icon.image = renderImage icon.tintColor = defaultIconColor @@ -98,12 +98,12 @@ open class RAMFumeAnimation: RAMItemAnimation { func playLabelAnimation(_ textLabel: UILabel) { let yPositionAnimation = createAnimation(Constants.AnimationKeys.PositionY, values: [textLabel.center.y as AnyObject, (textLabel.center.y - 60.0) as AnyObject], duration: duration) - yPositionAnimation.fillMode = kCAFillModeRemoved + yPositionAnimation.fillMode = CAMediaTimingFillMode.removed yPositionAnimation.isRemovedOnCompletion = true textLabel.layer.add(yPositionAnimation, forKey: nil) let scaleAnimation = createAnimation(Constants.AnimationKeys.Scale, values: [1.0 as AnyObject, 2.0 as AnyObject], duration: duration) - scaleAnimation.fillMode = kCAFillModeRemoved + scaleAnimation.fillMode = CAMediaTimingFillMode.removed scaleAnimation.isRemovedOnCompletion = true textLabel.layer.add(scaleAnimation, forKey: nil) @@ -116,8 +116,8 @@ open class RAMFumeAnimation: RAMItemAnimation { let animation = CAKeyframeAnimation(keyPath: keyPath) animation.values = values animation.duration = TimeInterval(duration) - animation.calculationMode = kCAAnimationCubic - animation.fillMode = kCAFillModeForwards + animation.calculationMode = CAAnimationCalculationMode.cubic + animation.fillMode = CAMediaTimingFillMode.forwards animation.isRemovedOnCompletion = false return animation } diff --git a/RAMAnimatedTabBarController/Animations/RotationAnimation/RAMRotationAnimation.swift b/RAMAnimatedTabBarController/Animations/RotationAnimation/RAMRotationAnimation.swift index 4e9518f0..de26c3fc 100755 --- a/RAMAnimatedTabBarController/Animations/RotationAnimation/RAMRotationAnimation.swift +++ b/RAMAnimatedTabBarController/Animations/RotationAnimation/RAMRotationAnimation.swift @@ -63,8 +63,8 @@ open class RAMRotationAnimation: RAMItemAnimation { textLabel.textColor = defaultTextColor if let iconImage = icon.image { - let renderMode = defaultIconColor.cgColor.alpha == 0 ? UIImageRenderingMode.alwaysOriginal : - UIImageRenderingMode.alwaysTemplate + let renderMode = defaultIconColor.cgColor.alpha == 0 ? UIImage.RenderingMode.alwaysOriginal : + UIImage.RenderingMode.alwaysTemplate let renderImage = iconImage.withRenderingMode(renderMode) icon.image = renderImage icon.tintColor = defaultIconColor diff --git a/RAMAnimatedTabBarController/Animations/TransitionAniamtions/RAMTransitionItemAnimations.swift b/RAMAnimatedTabBarController/Animations/TransitionAniamtions/RAMTransitionItemAnimations.swift index 380eb4c9..0b5df4ff 100755 --- a/RAMAnimatedTabBarController/Animations/TransitionAniamtions/RAMTransitionItemAnimations.swift +++ b/RAMAnimatedTabBarController/Animations/TransitionAniamtions/RAMTransitionItemAnimations.swift @@ -26,12 +26,12 @@ import UIKit open class RAMTransitionItemAnimations: RAMItemAnimation { /// Options for animating. Default TransitionNone - open var transitionOptions: UIViewAnimationOptions! + open var transitionOptions: UIView.AnimationOptions! override init() { super.init() - transitionOptions = UIViewAnimationOptions() + transitionOptions = UIView.AnimationOptions() } /** @@ -60,8 +60,8 @@ open class RAMTransitionItemAnimations: RAMItemAnimation { open override func deselectAnimation(_ icon: UIImageView, textLabel: UILabel, defaultTextColor: UIColor, defaultIconColor: UIColor) { if let iconImage = icon.image { - let renderMode = defaultIconColor.cgColor.alpha == 0 ? UIImageRenderingMode.alwaysOriginal : - UIImageRenderingMode.alwaysTemplate + let renderMode = defaultIconColor.cgColor.alpha == 0 ? UIImage.RenderingMode.alwaysOriginal : + UIImage.RenderingMode.alwaysTemplate let renderImage = iconImage.withRenderingMode(renderMode) icon.image = renderImage icon.tintColor = defaultIconColor @@ -97,7 +97,7 @@ open class RAMFlipLeftTransitionItemAnimations: RAMTransitionItemAnimations { public override init() { super.init() - transitionOptions = UIViewAnimationOptions.transitionFlipFromLeft + transitionOptions = UIView.AnimationOptions.transitionFlipFromLeft } } @@ -106,7 +106,7 @@ open class RAMFlipRightTransitionItemAnimations: RAMTransitionItemAnimations { public override init() { super.init() - transitionOptions = UIViewAnimationOptions.transitionFlipFromRight + transitionOptions = UIView.AnimationOptions.transitionFlipFromRight } } @@ -115,7 +115,7 @@ open class RAMFlipTopTransitionItemAnimations: RAMTransitionItemAnimations { public override init() { super.init() - transitionOptions = UIViewAnimationOptions.transitionFlipFromTop + transitionOptions = UIView.AnimationOptions.transitionFlipFromTop } } @@ -124,6 +124,6 @@ open class RAMFlipBottomTransitionItemAnimations: RAMTransitionItemAnimations { public override init() { super.init() - transitionOptions = UIViewAnimationOptions.transitionFlipFromBottom + transitionOptions = UIView.AnimationOptions.transitionFlipFromBottom } } diff --git a/RAMAnimatedTabBarController/RAMAnimatedTabBarController.swift b/RAMAnimatedTabBarController/RAMAnimatedTabBarController.swift index 6edde6d0..40509332 100644 --- a/RAMAnimatedTabBarController/RAMAnimatedTabBarController.swift +++ b/RAMAnimatedTabBarController/RAMAnimatedTabBarController.swift @@ -291,8 +291,8 @@ open class RAMAnimatedTabBarController: UITabBarController { } container.tag = index - let renderMode = item.iconColor.cgColor.alpha == 0 ? UIImageRenderingMode.alwaysOriginal : - UIImageRenderingMode.alwaysTemplate + let renderMode = item.iconColor.cgColor.alpha == 0 ? UIImage.RenderingMode.alwaysOriginal : + UIImage.RenderingMode.alwaysTemplate let iconImage = item.image ?? item.iconView?.icon.image let icon = UIImageView(image: iconImage?.withRenderingMode(renderMode)) @@ -347,32 +347,32 @@ open class RAMAnimatedTabBarController: UITabBarController { createConstraints(view, container: container, width: size.width, height: size.height, yOffset: yOffset) } - fileprivate func createConstraints(_ view: UIView, container: UIView, width: CGFloat? = nil, height: CGFloat? = nil, yOffset: CGFloat, heightRelation: NSLayoutRelation = .equal) { + fileprivate func createConstraints(_ view: UIView, container: UIView, width: CGFloat? = nil, height: CGFloat? = nil, yOffset: CGFloat, heightRelation: NSLayoutConstraint.Relation = .equal) { let constX = NSLayoutConstraint(item: view, - attribute: NSLayoutAttribute.centerX, - relatedBy: NSLayoutRelation.equal, + attribute: NSLayoutConstraint.Attribute.centerX, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: container, - attribute: NSLayoutAttribute.centerX, + attribute: NSLayoutConstraint.Attribute.centerX, multiplier: 1, constant: 0) container.addConstraint(constX) let constY = NSLayoutConstraint(item: view, - attribute: NSLayoutAttribute.centerY, - relatedBy: NSLayoutRelation.equal, + attribute: NSLayoutConstraint.Attribute.centerY, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: container, - attribute: NSLayoutAttribute.centerY, + attribute: NSLayoutConstraint.Attribute.centerY, multiplier: 1, constant: yOffset) container.addConstraint(constY) if let width = width { let constW = NSLayoutConstraint(item: view, - attribute: NSLayoutAttribute.width, - relatedBy: NSLayoutRelation.equal, + attribute: NSLayoutConstraint.Attribute.width, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, - attribute: NSLayoutAttribute.notAnAttribute, + attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: width) view.addConstraint(constW) @@ -380,10 +380,10 @@ open class RAMAnimatedTabBarController: UITabBarController { if let height = height { let constH = NSLayoutConstraint(item: view, - attribute: NSLayoutAttribute.height, + attribute: NSLayoutConstraint.Attribute.height, relatedBy: heightRelation, toItem: nil, - attribute: NSLayoutAttribute.notAnAttribute, + attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: height) view.addConstraint(constH) @@ -411,12 +411,12 @@ open class RAMAnimatedTabBarController: UITabBarController { if UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft{ constranints = NSLayoutConstraint.constraints(withVisualFormat: formatString, - options: NSLayoutFormatOptions.directionLeftToRight, + options: NSLayoutConstraint.FormatOptions.directionLeftToRight, metrics: nil, views: (containersDict as [String: AnyObject])) } else { constranints = NSLayoutConstraint.constraints(withVisualFormat: formatString, - options: NSLayoutFormatOptions.directionRightToLeft, + options: NSLayoutConstraint.FormatOptions.directionRightToLeft, metrics: nil, views: (containersDict as [String: AnyObject])) } @@ -440,10 +440,10 @@ open class RAMAnimatedTabBarController: UITabBarController { viewContainer.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor).isActive = true let constH = NSLayoutConstraint(item: viewContainer, - attribute: NSLayoutAttribute.height, - relatedBy: NSLayoutRelation.equal, + attribute: NSLayoutConstraint.Attribute.height, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, - attribute: NSLayoutAttribute.notAnAttribute, + attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 49) viewContainer.addConstraint(constH) @@ -464,7 +464,7 @@ open class RAMAnimatedTabBarController: UITabBarController { if items[currentIndex].isEnabled == false { return } - let controller = childViewControllers[currentIndex] + let controller = children[currentIndex] if let shouldSelect = delegate?.tabBarController?(self, shouldSelect: controller) , !shouldSelect { diff --git a/RAMAnimatedTabBarController/RAMBadge/RAMBadge.swift b/RAMAnimatedTabBarController/RAMBadge/RAMBadge.swift index ffd0d616..b080b2c1 100644 --- a/RAMAnimatedTabBarController/RAMBadge/RAMBadge.swift +++ b/RAMAnimatedTabBarController/RAMBadge/RAMBadge.swift @@ -60,20 +60,20 @@ open class RAMBadge: UILabel { internal func createSizeConstraints(_ size: CGSize) { let widthConstraint = NSLayoutConstraint( item: self, - attribute: NSLayoutAttribute.width, - relatedBy: NSLayoutRelation.greaterThanOrEqual, + attribute: NSLayoutConstraint.Attribute.width, + relatedBy: NSLayoutConstraint.Relation.greaterThanOrEqual, toItem: nil, - attribute: NSLayoutAttribute.notAnAttribute, + attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: size.width) addConstraint(widthConstraint) let heightConstraint = NSLayoutConstraint( item: self, - attribute: NSLayoutAttribute.height, - relatedBy: NSLayoutRelation.equal, + attribute: NSLayoutConstraint.Attribute.height, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, - attribute: NSLayoutAttribute.notAnAttribute, + attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: size.height) addConstraint(heightConstraint) @@ -93,20 +93,20 @@ open class RAMBadge: UILabel { // create constraints let top = NSLayoutConstraint(item: self, - attribute: NSLayoutAttribute.top, - relatedBy: NSLayoutRelation.equal, + attribute: NSLayoutConstraint.Attribute.top, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: onView, - attribute: NSLayoutAttribute.top, + attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: 3) onView.addConstraint(top) topConstraint = top let centerX = NSLayoutConstraint(item: self, - attribute: NSLayoutAttribute.centerX, - relatedBy: NSLayoutRelation.equal, + attribute: NSLayoutConstraint.Attribute.centerX, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: onView, - attribute: NSLayoutAttribute.centerX, + attribute: NSLayoutConstraint.Attribute.centerX, multiplier: 1, constant: 10) onView.addConstraint(centerX) diff --git a/RAMAnimatedTabBarDemo/RAMAnimatedTabBarDemo.xcodeproj/project.pbxproj b/RAMAnimatedTabBarDemo/RAMAnimatedTabBarDemo.xcodeproj/project.pbxproj index 545e911f..9d328b18 100644 --- a/RAMAnimatedTabBarDemo/RAMAnimatedTabBarDemo.xcodeproj/project.pbxproj +++ b/RAMAnimatedTabBarDemo/RAMAnimatedTabBarDemo.xcodeproj/project.pbxproj @@ -351,17 +351,18 @@ TargetAttributes = { 5A1F33B82126AA3D004B8735 = { CreatedOnToolsVersion = 9.4; + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; TestTargetID = CE4146711A1B923D0037F03C; }; 84D4B79C1DB0D35500EE38C6 = { CreatedOnToolsVersion = 8.0; - LastSwiftMigration = 0910; + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; }; CE4146711A1B923D0037F03C = { CreatedOnToolsVersion = 6.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 1000; }; }; }; @@ -510,7 +511,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.AnimatedTabBarTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Animated Tab Bar.app/Animated Tab Bar"; }; @@ -535,7 +536,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.AnimatedTabBarTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Animated Tab Bar.app/Animated Tab Bar"; }; @@ -564,8 +565,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -594,8 +594,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.RAMAnimatedTabBarController; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -721,7 +720,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.dev; PRODUCT_NAME = "Animated Tab Bar"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -740,7 +739,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.dev; PRODUCT_NAME = "Animated Tab Bar"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/RAMAnimatedTabBarDemo/RAMAnimatedTabBarDemo/AppDelegate.swift b/RAMAnimatedTabBarDemo/RAMAnimatedTabBarDemo/AppDelegate.swift index 6e06043f..941002df 100644 --- a/RAMAnimatedTabBarDemo/RAMAnimatedTabBarDemo/AppDelegate.swift +++ b/RAMAnimatedTabBarDemo/RAMAnimatedTabBarDemo/AppDelegate.swift @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { + public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { return true } }