From d4556f40101eb3627e8ea42d236fc2337ef1a7fb Mon Sep 17 00:00:00 2001 From: Naoki Morita Date: Sun, 11 Sep 2016 18:36:47 +0900 Subject: [PATCH 1/3] Update to latest syntax --- .gitignore | 2 + Demo/AppDelegate.swift | 12 +-- Demo/ViewController.swift | 84 +++++++++---------- SwiftyDrop.xcodeproj/project.pbxproj | 15 +++- .../xcschemes/SwiftyDrop.xcscheme | 10 +-- SwiftyDrop/Drop.swift | 75 +++++++++-------- 6 files changed, 107 insertions(+), 91 deletions(-) diff --git a/.gitignore b/.gitignore index 8615121..49f5752 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ DerivedData # Carthage/Checkouts Carthage/Build + +.DS_Store diff --git a/Demo/AppDelegate.swift b/Demo/AppDelegate.swift index fa47b7d..f5f59a3 100644 --- a/Demo/AppDelegate.swift +++ b/Demo/AppDelegate.swift @@ -13,30 +13,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/Demo/ViewController.swift b/Demo/ViewController.swift index a54253c..ae25f6e 100644 --- a/Demo/ViewController.swift +++ b/Demo/ViewController.swift @@ -13,77 +13,77 @@ class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - navigationController?.navigationBarHidden = true - let tapRecognizer = UITapGestureRecognizer(target: self, action: "upAllDrops:") + navigationController?.isNavigationBarHidden = true + let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(ViewController.upAllDrops(_:))) view.addGestureRecognizer(tapRecognizer) } - @IBAction func showStatesAlert(sender: AnyObject) { - let defaultAction = UIAlertAction(title: "Default", style: .Default) { [unowned self] action -> Void in + @IBAction func showStatesAlert(_ sender: AnyObject) { + let defaultAction = UIAlertAction(title: "Default", style: .default) { [unowned self] action -> Void in Drop.down(self.sampleText()) } - let infoAction = UIAlertAction(title: "Info", style: .Default) { [unowned self] action -> Void in - Drop.down(self.sampleText(), state: .Info) + let infoAction = UIAlertAction(title: "Info", style: .default) { _ in + Drop.down(self.sampleText(), state: .info) } - let successAction = UIAlertAction(title: "Success", style: .Default) { [unowned self] action -> Void in - Drop.down(self.sampleText(), state: .Success) + let successAction = UIAlertAction(title: "Success", style: .default) { _ in + Drop.down(self.sampleText(), state: .success) } - let warningAction = UIAlertAction(title: "Warning", style: .Default) { [unowned self] action -> Void in - Drop.down(self.sampleText(), state: .Warning) + let warningAction = UIAlertAction(title: "Warning", style: .default) { _ in + Drop.down(self.sampleText(), state: .warning) } - let errorAction = UIAlertAction(title: "Error", style: .Default) { [unowned self] action -> Void in - Drop.down(self.sampleText(), state: .Error) + let errorAction = UIAlertAction(title: "Error", style: .default) { _ in + Drop.down(self.sampleText(), state: .error) } - let colorAction = UIAlertAction(title: "Custom color", style: .Default) { [unowned self] action -> Void in + let colorAction = UIAlertAction(title: "Custom color", style: .default) { _ in let r = CGFloat(arc4random_uniform(256)) let g = CGFloat(arc4random_uniform(256)) let b = CGFloat(arc4random_uniform(256)) let color = UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: 1.0) - Drop.down(self.sampleText(), state: .Color(color)) + Drop.down(self.sampleText(), state: .color(color)) } - let actionableAction = UIAlertAction(title: "Action", style: .Default) { [unowned self] action -> Void in + let actionableAction = UIAlertAction(title: "Action", style: .default) { [unowned self] action -> Void in Drop.down(self.sampleText()) { - let action = UIAlertAction(title: "OK", style: .Default, handler: nil) - let controller = UIAlertController(title: "Action", message: "Action fired!", preferredStyle: .Alert) + let action = UIAlertAction(title: "OK", style: .default, handler: nil) + let controller = UIAlertController(title: "Action", message: "Action fired!", preferredStyle: .alert) controller.addAction(action) - self.presentViewController(controller, animated: true, completion: nil) + self.present(controller, animated: true, completion: nil) } } - let blurAction = UIAlertAction(title: "Blur", style: .Default) { [unowned self] action -> Void in - Drop.down(self.sampleText(), state: .Blur(.Light)) + let blurAction = UIAlertAction(title: "Blur", style: .default) { _ in + Drop.down(self.sampleText(), state: .blur(.light)) } - let customAction = UIAlertAction(title: "Custom", style: .Default) { [unowned self] action -> Void in + let customAction = UIAlertAction(title: "Custom", style: .default) { _ in enum Custom: DropStatable { - case BlackGreen + case blackGreen var backgroundColor: UIColor? { switch self { - case .BlackGreen: return .blackColor() + case .blackGreen: return .black } } var font: UIFont? { switch self { - case .BlackGreen: return UIFont(name: "HelveticaNeue-Light", size: 24.0) + case .blackGreen: return UIFont(name: "HelveticaNeue-Light", size: 24.0) } } var textColor: UIColor? { switch self { - case .BlackGreen: return .greenColor() + case .blackGreen: return .green } } var blurEffect: UIBlurEffect? { switch self { - case .BlackGreen: return nil + case .blackGreen: return nil } } } - Drop.down(self.sampleText(), state: Custom.BlackGreen) + Drop.down(self.sampleText(), state: Custom.blackGreen) } - let durationAction = UIAlertAction(title: "Duration", style: .Default) { [unowned self] action -> Void in + let durationAction = UIAlertAction(title: "Duration", style: .default) { [unowned self] action -> Void in self.showDurationAlert() } - let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) + let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) - let controller = UIAlertController(title: "Samples", message: "Select to show drop down message.", preferredStyle: .ActionSheet) + let controller = UIAlertController(title: "Samples", message: "Select to show drop down message.", preferredStyle: .actionSheet) for action in [defaultAction, infoAction, successAction, warningAction, errorAction, colorAction, actionableAction, blurAction, customAction, durationAction, cancelAction] { controller.addAction(action) } @@ -93,33 +93,33 @@ class ViewController: UIViewController { func showDurationAlert() { let durations = [0.5, 1.0, 2.0, 4.0, 6.0, 10.0, 20.0] let actions = durations.map { seconds in - return UIAlertAction(title: "\(seconds)", style: .Default) { [unowned self] action -> Void in - Drop.down(self.sampleText(), state: .Default, duration: seconds) + return UIAlertAction(title: "\(seconds)", style: .default) { _ in + Drop.down(self.sampleText(), state: .default, duration: seconds) } } - let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) + let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) - let controller = UIAlertController(title: "Duration", message: "Select to duration. Default is 4 seconds.", preferredStyle: .ActionSheet) + let controller = UIAlertController(title: "Duration", message: "Select to duration. Default is 4 seconds.", preferredStyle: .actionSheet) for action in [cancelAction] + actions { controller.addAction(action) } showAlert(controller) } - func showAlert(controller: UIAlertController, sourceView: UIView? = nil) { - if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Pad { + func showAlert(_ controller: UIAlertController, sourceView: UIView? = nil) { + if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad { if let sourceView = sourceView { - let rect = sourceView.convertRect(sourceView.bounds, toView: view) + let rect = sourceView.convert(sourceView.bounds, to: view) controller.popoverPresentationController?.sourceView = view controller.popoverPresentationController?.sourceRect = rect } } - presentViewController(controller, animated: true, completion: nil) + present(controller, animated: true, completion: nil) } - func upAllDrops(sender: AnyObject) { - if let hidden = navigationController?.navigationBarHidden { + func upAllDrops(_ sender: AnyObject) { + if let hidden = navigationController?.isNavigationBarHidden { navigationController?.setNavigationBarHidden(!hidden, animated: true) } @@ -129,7 +129,7 @@ class ViewController: UIViewController { func sampleText() -> String { let text = "Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda." let length = Int(arc4random_uniform(100)) + 10 - let end = text.startIndex.advancedBy(length) - return text.substringWithRange(Range(start: text.startIndex, end: end)) + let end = text.characters.index(text.startIndex, offsetBy: length) + return text.substring(with: (text.startIndex ..< end)) } } diff --git a/SwiftyDrop.xcodeproj/project.pbxproj b/SwiftyDrop.xcodeproj/project.pbxproj index e1900a8..f5db767 100644 --- a/SwiftyDrop.xcodeproj/project.pbxproj +++ b/SwiftyDrop.xcodeproj/project.pbxproj @@ -166,14 +166,16 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0630; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = MORITANAOKI; TargetAttributes = { 908543641B3690870037B0FD = { CreatedOnToolsVersion = 6.3.2; + LastSwiftMigration = 0800; }; 90E5BA281B35791A0075B777 = { CreatedOnToolsVersion = 6.3.2; + LastSwiftMigration = 0800; }; }; }; @@ -253,6 +255,7 @@ 908543791B3690870037B0FD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -269,6 +272,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "--PRODUCT-BUNDLE-IDENTIFIER-"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -277,6 +281,7 @@ 9085437A1B3690870037B0FD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -289,6 +294,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "--PRODUCT-BUNDLE-IDENTIFIER-"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -307,8 +313,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"; @@ -353,8 +361,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"; @@ -373,6 +383,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -394,6 +405,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.molabo.SwiftyDrop; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -409,6 +421,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.molabo.SwiftyDrop; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/SwiftyDrop.xcodeproj/xcshareddata/xcschemes/SwiftyDrop.xcscheme b/SwiftyDrop.xcodeproj/xcshareddata/xcschemes/SwiftyDrop.xcscheme index 626177b..c7f80c7 100644 --- a/SwiftyDrop.xcodeproj/xcshareddata/xcschemes/SwiftyDrop.xcscheme +++ b/SwiftyDrop.xcodeproj/xcshareddata/xcschemes/SwiftyDrop.xcscheme @@ -1,6 +1,6 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -66,11 +66,11 @@ Void public final class Drop: UIView { static let PRESET_DURATION: TimeInterval = 4.0 - private var statusLabel: UILabel! - private let statusTopMargin: CGFloat = 10.0 - private let statusBottomMargin: CGFloat = 10.0 - private var minimumHeight: CGFloat { return UIApplication.shared().statusBarFrame.height + 44.0 } - private var topConstraint: NSLayoutConstraint? - private var heightConstraint: NSLayoutConstraint? + fileprivate var statusLabel: UILabel! + fileprivate let statusTopMargin: CGFloat = 10.0 + fileprivate let statusBottomMargin: CGFloat = 10.0 + fileprivate var minimumHeight: CGFloat { return UIApplication.shared.statusBarFrame.height + 44.0 } + fileprivate var topConstraint: NSLayoutConstraint? + fileprivate var heightConstraint: NSLayoutConstraint? - private var duration: TimeInterval = Drop.PRESET_DURATION + fileprivate var duration: TimeInterval = Drop.PRESET_DURATION - private var upTimer: Timer? - private var startTop: CGFloat? + fileprivate var upTimer: Timer? + fileprivate var startTop: CGFloat? - private var action: DropAction? + fileprivate var action: DropAction? convenience init(duration: Double) { self.init(frame: CGRect.zero) self.duration = duration scheduleUpTimer(duration) - NotificationCenter.default.addObserver(self, selector: "applicationDidEnterBackground:", name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil) - NotificationCenter.default.addObserver(self, selector: "deviceOrientationDidChange:", name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(UIApplicationDelegate.applicationDidEnterBackground(_:)), name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(Drop.deviceOrientationDidChange(_:)), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil) } override init(frame: CGRect) { @@ -109,23 +109,23 @@ public final class Drop: UIView { } } - private func scheduleUpTimer(_ after: Double) { + fileprivate func scheduleUpTimer(_ after: Double) { scheduleUpTimer(after, interval: 0.25) } - private func scheduleUpTimer(_ after: Double, interval: Double) { + fileprivate func scheduleUpTimer(_ after: Double, interval: Double) { stopUpTimer() - upTimer = Timer.scheduledTimer(timeInterval: after, target: self, selector: "upFromTimer:", userInfo: interval, repeats: false) + upTimer = Timer.scheduledTimer(timeInterval: after, target: self, selector: #selector(self.upFromTimer(_:)), userInfo: interval, repeats: false) } - private func stopUpTimer() { + fileprivate func stopUpTimer() { upTimer?.invalidate() upTimer = nil } - private func updateHeight() { + fileprivate func updateHeight() { var height: CGFloat = 0.0 - height += UIApplication.shared().statusBarFrame.height + height += UIApplication.shared.statusBarFrame.height height += statusTopMargin height += statusLabel.frame.size.height height += statusBottomMargin @@ -146,7 +146,7 @@ extension Drop { private class func show(_ status: String, state: DropStatable, duration: Double, action: DropAction?) { self.upAll() let drop = Drop(duration: duration) - UIApplication.shared().keyWindow?.addSubview(drop) + UIApplication.shared.keyWindow?.addSubview(drop) guard let window = drop.window else { return } let heightConstraint = NSLayoutConstraint(item: drop, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 100.0) @@ -179,7 +179,7 @@ extension Drop { ) } - private class func up(_ drop: Drop, interval: TimeInterval) { + class func up(_ drop: Drop, interval: TimeInterval) { guard let heightConstant = drop.heightConstraint?.constant else { return } drop.topConstraint?.constant = -heightConstant UIView.animate( @@ -195,8 +195,8 @@ extension Drop { } } - public class func upAll() { - guard let window = UIApplication.shared().keyWindow else { return } + class func upAll() { + guard let window = UIApplication.shared.keyWindow else { return } for view in window.subviews { if let drop = view as? Drop { drop.up() @@ -206,7 +206,7 @@ extension Drop { } extension Drop { - private func setup(_ status: String, state: DropStatable) { + fileprivate func setup(_ status: String, state: DropStatable) { self.translatesAutoresizingMaskIntoConstraints = false var labelParentView: UIView = self @@ -217,7 +217,7 @@ extension Drop { addConstraints( [ NSLayoutConstraint(item: backgroundView, attribute: .left, relatedBy: .equal, toItem: self, attribute: .left, multiplier: 1.0, constant: 0.0), - NSLayoutConstraint(item: backgroundView, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: -UIScreen.main().bounds.height), + NSLayoutConstraint(item: backgroundView, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: -UIScreen.main.bounds.height), NSLayoutConstraint(item: backgroundView, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1.0, constant: 0.0), NSLayoutConstraint(item: backgroundView, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottom, multiplier: 1.0, constant: 0.0), ] @@ -230,7 +230,7 @@ extension Drop { addConstraints( [ NSLayoutConstraint(item: visualEffectView, attribute: .left, relatedBy: .equal, toItem: self, attribute: .left, multiplier: 1.0, constant: 0.0), - NSLayoutConstraint(item: visualEffectView, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: -UIScreen.main().bounds.height), + NSLayoutConstraint(item: visualEffectView, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: -UIScreen.main.bounds.height), NSLayoutConstraint(item: visualEffectView, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1.0, constant: 0.0), NSLayoutConstraint(item: visualEffectView, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottom, multiplier: 1.0, constant: 0.0), ] @@ -258,7 +258,7 @@ extension Drop { statusLabel.font = state.font ?? UIFont.systemFont(ofSize: 17.0) statusLabel.textAlignment = .center statusLabel.text = status - statusLabel.textColor = state.textColor ?? .white() + statusLabel.textColor = state.textColor ?? .white labelParentView.addSubview(statusLabel) labelParentView.addConstraints( [ @@ -270,8 +270,8 @@ extension Drop { self.statusLabel = statusLabel self.layoutIfNeeded() - self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "up:")) - self.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: "pan:")) + self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.up(_:)))) + self.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.pan(_:)))) } } @@ -299,11 +299,12 @@ extension Drop { } case .ended: startTop = nil - if topConstraint?.constant < 0.0 { + guard let topConstraint = topConstraint else { return } + if topConstraint.constant < 0.0 { scheduleUpTimer(0.0, interval: 0.1) } else { scheduleUpTimer(duration) - topConstraint?.constant = 0.0 + topConstraint.constant = 0.0 UIView.animate( withDuration: TimeInterval(0.1), delay: TimeInterval(0.0), From 5b1ddfc5d5a03d83b82c2dec10fd3b4d66046363 Mon Sep 17 00:00:00 2001 From: Naoki Morita Date: Sun, 11 Sep 2016 18:41:29 +0900 Subject: [PATCH 2/3] Change accessor modifier --- SwiftyDrop/Drop.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SwiftyDrop/Drop.swift b/SwiftyDrop/Drop.swift index 55348b6..f38a64f 100644 --- a/SwiftyDrop/Drop.swift +++ b/SwiftyDrop/Drop.swift @@ -143,7 +143,7 @@ extension Drop { show(status, state: state, duration: duration, action: action) } - private class func show(_ status: String, state: DropStatable, duration: Double, action: DropAction?) { + fileprivate class func show(_ status: String, state: DropStatable, duration: Double, action: DropAction?) { self.upAll() let drop = Drop(duration: duration) UIApplication.shared.keyWindow?.addSubview(drop) @@ -179,7 +179,7 @@ extension Drop { ) } - class func up(_ drop: Drop, interval: TimeInterval) { + fileprivate class func up(_ drop: Drop, interval: TimeInterval) { guard let heightConstant = drop.heightConstraint?.constant else { return } drop.topConstraint?.constant = -heightConstant UIView.animate( @@ -195,7 +195,7 @@ extension Drop { } } - class func upAll() { + public class func upAll() { guard let window = UIApplication.shared.keyWindow else { return } for view in window.subviews { if let drop = view as? Drop { From 51ec9ead79cd1e28d819c430c29ef93a27f789c2 Mon Sep 17 00:00:00 2001 From: Naoki Morita Date: Mon, 19 Sep 2016 05:21:24 +0900 Subject: [PATCH 3/3] Fix strange animation --- SwiftyDrop/Drop.swift | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/SwiftyDrop/Drop.swift b/SwiftyDrop/Drop.swift index f38a64f..6e87af1 100644 --- a/SwiftyDrop/Drop.swift +++ b/SwiftyDrop/Drop.swift @@ -167,14 +167,17 @@ extension Drop { drop.setup(status, state: state) drop.action = action drop.updateHeight() - + + guard let superview = drop.superview else { return } + superview.layoutIfNeeded() + topConstraint.constant = 0.0 UIView.animate( withDuration: TimeInterval(0.25), delay: TimeInterval(0.0), options: [.allowUserInteraction, .curveEaseOut], - animations: { [weak drop] () -> Void in - if let drop = drop { drop.layoutIfNeeded() } + animations: { _ in + superview.layoutIfNeeded() }, completion: nil ) } @@ -182,14 +185,15 @@ extension Drop { fileprivate class func up(_ drop: Drop, interval: TimeInterval) { guard let heightConstant = drop.heightConstraint?.constant else { return } drop.topConstraint?.constant = -heightConstant + + guard let superview = drop.superview else { return } + UIView.animate( withDuration: interval, delay: TimeInterval(0.0), options: [.allowUserInteraction, .curveEaseIn], - animations: { [weak drop] () -> Void in - if let drop = drop { - drop.layoutIfNeeded() - } + animations: { _ in + superview.layoutIfNeeded() }) { [weak drop] finished -> Void in if let drop = drop { drop.removeFromSuperview() } } @@ -304,13 +308,14 @@ extension Drop { scheduleUpTimer(0.0, interval: 0.1) } else { scheduleUpTimer(duration) + guard let superview = superview else { return } topConstraint.constant = 0.0 UIView.animate( withDuration: TimeInterval(0.1), delay: TimeInterval(0.0), options: [.allowUserInteraction, .curveEaseOut], - animations: { [weak self] () -> Void in - if let s = self { s.layoutIfNeeded() } + animations: { _ in + superview.layoutIfNeeded() }, completion: nil ) }