From 8df42d8e31a82bb7e3d5ee182396e8699a6fb05b Mon Sep 17 00:00:00 2001 From: Samuel Hyeman Date: Sun, 14 Jun 2020 17:07:03 +0100 Subject: [PATCH 1/3] updated to swift 5 --- Classes/YBAlertController.swift | 210 +++++++++--------- .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + 3 files changed, 121 insertions(+), 104 deletions(-) create mode 100644 Example/Pods/Pods.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 Example/Pods/Pods.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Classes/YBAlertController.swift b/Classes/YBAlertController.swift index d4ba339..cf92e61 100644 --- a/Classes/YBAlertController.swift +++ b/Classes/YBAlertController.swift @@ -6,6 +6,8 @@ // Copyright © 2016年 Yabuzaki Yuta. All rights reserved. // +import Foundation + import UIKit public enum YBAlertControllerStyle { @@ -26,17 +28,17 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { // titleLabel public var titleFont = UIFont(name: "Avenir Next", size: 15) - public var titleTextColor = UIColor.blackColor() + public var titleTextColor = UIColor.black // message public var message:String? public var messageLabel = UILabel() public var messageFont = UIFont(name: "Avenir Next", size: 13) - public var messageTextColor = UIColor.lightGrayColor() + public var messageTextColor = UIColor.lightGray // button public var buttonHeight:CGFloat = 50 - public var buttonTextColor = UIColor.blackColor() + public var buttonTextColor = UIColor.black public var buttonIconColor:UIColor? public var buttons = [YBButton]() public var buttonFont = UIFont(name: "Avenir Next", size: 15) @@ -44,7 +46,7 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { // cancelButton public var cancelButtonTitle:String? public var cancelButtonFont = UIFont(name: "Avenir Next", size: 14) - public var cancelButtonTextColor = UIColor.darkGrayColor() + public var cancelButtonTextColor = UIColor.darkGray public var animated = true public var containerView = UIView() @@ -68,17 +70,17 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { public init() { super.init(nibName: nil, bundle: nil) - view.frame = UIScreen.mainScreen().bounds + view.frame = UIScreen.main.bounds - containerView.backgroundColor = UIColor.whiteColor() + containerView.backgroundColor = UIColor.white containerView.clipsToBounds = true - let tapGesture = UITapGestureRecognizer(target: self, action: Selector("dismiss")) + let tapGesture = UITapGestureRecognizer(target: self, action: Selector(("dismiss"))) tapGesture.numberOfTapsRequired = 1 tapGesture.delegate = self self.view.addGestureRecognizer(tapGesture) - NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("changedOrientation:"), name: UIDeviceOrientationDidChangeNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: Selector(("changedOrientation:")), name: UIDevice.orientationDidChangeNotification, object: nil) } public convenience init(style: YBAlertControllerStyle) { @@ -94,18 +96,18 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { } deinit { - NSNotificationCenter.defaultCenter().removeObserver(self) + NotificationCenter.default.removeObserver(self) } func changedOrientation(notification: NSNotification) { if showing && style == YBAlertControllerStyle.ActionSheet { let value = currentOrientation?.rawValue - UIDevice.currentDevice().setValue(value, forKey: "orientation") + UIDevice.current.setValue(value, forKey: "orientation") return } } - public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool { + public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { if touchingOutsideDismiss == false { return false } if touch.view != gestureRecognizer.view { return false } return true @@ -124,19 +126,19 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { initContainerView() if style == YBAlertControllerStyle.ActionSheet { - UIView.animateWithDuration(0.3, + UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0, - options: .CurveEaseIn, + options: .curveEaseIn, animations: { self.containerView.frame.origin.y = self.view.frame.height - self.containerView.frame.height - self.getTopViewController()?.view.transform = CGAffineTransformMakeScale(0.9, 0.9) + self.getTopViewController()?.view.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) }, completion: { (finished) in if self.animated { self.startButtonAppearAnimation() - if let cancelTitle = self.cancelButtonTitle where cancelTitle != "" { + if let cancelTitle = self.cancelButtonTitle, cancelTitle != "" { self.startCancelButtonAppearAnimation() } @@ -145,21 +147,21 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { ) } else { self.containerView.frame.origin.y = self.view.frame.height/2 - self.containerView.frame.height/2 - containerView.transform = CGAffineTransformMakeScale(0.5, 0.5) + containerView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5) containerView.alpha = 0.0 - UIView.animateWithDuration(0.3, + UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0, - options: .CurveEaseIn, + options: .curveEaseIn, animations: { self.containerView.alpha = 1.0 - self.containerView.transform = CGAffineTransformMakeScale(1, 1) + self.containerView.transform = CGAffineTransform(scaleX: 1, y: 1) }, completion: { (finished) in if self.animated { self.startButtonAppearAnimation() - if let cancelTitle = self.cancelButtonTitle where cancelTitle != "" { + if let cancelTitle = self.cancelButtonTitle, cancelTitle != "" { self.startCancelButtonAppearAnimation() } @@ -172,24 +174,24 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { public func dismiss() { showing = false if let statusBarStyle = currentStatusBarStyle { - UIApplication.sharedApplication().statusBarStyle = statusBarStyle + UIApplication.shared.statusBarStyle = statusBarStyle } if style == .ActionSheet { - UIView.animateWithDuration(0.2, + UIView.animate(withDuration: 0.2, animations: { self.containerView.frame.origin.y = self.view.frame.height self.view.backgroundColor = UIColor(white: 0, alpha: 0) - self.getTopViewController()?.view.transform = CGAffineTransformMakeScale(1.0, 1.0) + self.getTopViewController()?.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) }, completion: { (finished) in self.view.removeFromSuperview() }) } else { - UIView.animateWithDuration(0.2, + UIView.animate(withDuration: 0.2, animations: { self.view.backgroundColor = UIColor(white: 0, alpha: 0) - self.containerView.transform = CGAffineTransformMakeScale(0.5, 0.5) + self.containerView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5) self.containerView.alpha = 0 }, completion: { (finished) in @@ -199,7 +201,7 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { } private func getTopViewController() -> UIViewController? { - var topVC = UIApplication.sharedApplication().keyWindow?.rootViewController + var topVC = UIApplication.shared.keyWindow?.rootViewController while topVC?.presentedViewController != nil { topVC = topVC?.presentedViewController } @@ -219,56 +221,56 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { instance = self let viewWidth = (style == .ActionSheet) ? view.frame.width : view.frame.width * 0.9 - currentOrientation = UIDevice.currentDevice().orientation - let orientation = UIApplication.sharedApplication().statusBarOrientation - if orientation == UIInterfaceOrientation.Portrait { - currentOrientation = UIDeviceOrientation.Portrait + currentOrientation = UIDevice.current.orientation + let orientation = UIApplication.shared.statusBarOrientation + if orientation == UIInterfaceOrientation.portrait { + currentOrientation = UIDeviceOrientation.portrait } var posY:CGFloat = 0 - if let title = title where title != "" { + if let title = title, title != "" { let titleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: viewWidth, height: buttonHeight*0.92)) titleLabel.text = title titleLabel.font = titleFont - titleLabel.textAlignment = .Center - titleLabel.autoresizingMask = [.FlexibleRightMargin, .FlexibleLeftMargin] + titleLabel.textAlignment = .center + titleLabel.autoresizingMask = [.flexibleRightMargin, .flexibleLeftMargin] titleLabel.textColor = titleTextColor containerView.addSubview(titleLabel) let line = UIView(frame: CGRect(x: 0, y: titleLabel.frame.height, width: viewWidth, height: 1)) line.backgroundColor = UIColor(white: 0.9, alpha: 1.0) - line.autoresizingMask = [.FlexibleWidth] + line.autoresizingMask = [.flexibleWidth] containerView.addSubview(line) posY = titleLabel.frame.height + line.frame.height } else { posY = 0 } - if let message = message where message != "" { + if let message = message, message != "" { let paddingY:CGFloat = 8 let paddingX:CGFloat = 10 messageLabel.font = messageFont - messageLabel.textColor = UIColor.grayColor() + messageLabel.textColor = UIColor.gray messageLabel.translatesAutoresizingMaskIntoConstraints = false messageLabel.text = message messageLabel.numberOfLines = 0 messageLabel.textColor = messageTextColor - let f = CGSizeMake(viewWidth - paddingX*2, CGFloat.max) + let f = CGSize(width: viewWidth - paddingX*2, height: CGFloat.greatestFiniteMagnitude) let rect = messageLabel.sizeThatFits(f) messageLabel.frame = CGRect(x: paddingX, y: posY + paddingY, width: rect.width, height: rect.height) containerView.addSubview(messageLabel) containerView.addConstraints([ - NSLayoutConstraint(item: messageLabel, attribute: .RightMargin, relatedBy: NSLayoutRelation.Equal, toItem: containerView, attribute: .RightMargin, multiplier: 1, constant: -paddingX), - NSLayoutConstraint(item: messageLabel, attribute: .LeftMargin, relatedBy: .Equal, toItem: containerView, attribute: .LeftMargin, multiplier: 1.0, constant: paddingX), - NSLayoutConstraint(item: messageLabel, attribute: .Top, relatedBy: .Equal, toItem: containerView, attribute: .Top, multiplier: 1.0, constant: posY + paddingY), - NSLayoutConstraint(item: messageLabel, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .Height, multiplier: 1.0, constant: rect.height) + NSLayoutConstraint(item: messageLabel, attribute: .rightMargin, relatedBy: NSLayoutConstraint.Relation.equal, toItem: containerView, attribute: .rightMargin, multiplier: 1, constant: -paddingX), + NSLayoutConstraint(item: messageLabel, attribute: .leftMargin, relatedBy: .equal, toItem: containerView, attribute: .leftMargin, multiplier: 1.0, constant: paddingX), + NSLayoutConstraint(item: messageLabel, attribute: .top, relatedBy: .equal, toItem: containerView, attribute: .top, multiplier: 1.0, constant: posY + paddingY), + NSLayoutConstraint(item: messageLabel, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: rect.height) ]) posY = messageLabel.frame.maxY + paddingY let line = UIView(frame: CGRect(x: 0, y: posY, width: viewWidth, height: 1)) line.backgroundColor = UIColor(white: 0.9, alpha: 1.0) - line.autoresizingMask = [.FlexibleWidth] + line.autoresizingMask = [.flexibleWidth] containerView.addSubview(line) posY += line.frame.height @@ -276,7 +278,7 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { for i in 0..Void) { + public func addButton(icon:UIImage?, title:String, action:@escaping ()->Void) { let button = YBButton(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: buttonHeight), icon: icon, text: title) button.actionType = YBButtonActionType.Closure button.action = action button.buttonColor = buttonIconColor button.buttonFont = buttonFont - button.addTarget(self, action: Selector("buttonTapped:"), forControlEvents: .TouchUpInside) + button.addTarget(self, action: Selector(("buttonTapped:")), for: .touchUpInside) buttons.append(button) } @@ -388,16 +390,16 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { button.target = target button.selector = selector button.buttonFont = buttonFont - button.addTarget(self, action: Selector("buttonTapped:"), forControlEvents: .TouchUpInside) + button.addTarget(self, action: Selector(("buttonTapped:")), for: .touchUpInside) buttons.append(button) } - public func addButton(title:String, action:()->Void) { - addButton(nil, title: title, action: action) + public func addButton(title:String, action:@escaping ()->Void) { + addButton(icon: nil, title: title, action: action) } public func addButton(title:String, target:AnyObject, selector:Selector) { - addButton(nil, title: title, target: target, selector: selector) + addButton(icon: nil, title: title, target: target, selector: selector) } func buttonTapped(button:YBButton) { @@ -405,7 +407,7 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { button.action() } else if button.actionType == YBButtonActionType.Selector { let control = UIControl() - control.sendAction(button.selector, to: button.target, forEvent: nil) + control.sendAction(button.selector, to: button.target, for: nil) } dismiss() } @@ -413,15 +415,15 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { public class YBButton : UIButton { - override public var highlighted : Bool { + override public var isHighlighted : Bool { didSet { - alpha = highlighted ? 0.3 : 1.0 + alpha = isHighlighted ? 0.3 : 1.0 } } var buttonColor:UIColor? { didSet { if let buttonColor = buttonColor { - iconImageView.image = icon?.imageWithRenderingMode(.AlwaysTemplate) + iconImageView.image = icon?.withRenderingMode(.alwaysTemplate) iconImageView.tintColor = buttonColor dotView.dotColor = buttonColor } else { @@ -454,33 +456,33 @@ public class YBButton : UIButton { addSubview(iconImageView) dotView.frame = iconImageView.frame - dotView.backgroundColor = UIColor.clearColor() - dotView.hidden = true + dotView.backgroundColor = UIColor.clear + dotView.isHidden = true addSubview(dotView) let labelHeight = frame.height * 0.8 textLabel.frame = CGRect(x: iconImageView.frame.maxX + 11, y: frame.midY - labelHeight/2, width: frame.width - iconImageView.frame.maxX, height: labelHeight) textLabel.text = text - textLabel.textColor = UIColor.blackColor() + textLabel.textColor = UIColor.black textLabel.font = buttonFont addSubview(textLabel) } func appear() { - iconImageView.transform = CGAffineTransformMakeScale(0, 0) - textLabel.transform = CGAffineTransformMakeScale(0, 0) - dotView.transform = CGAffineTransformMakeScale(0, 0) - dotView.hidden = false - UIView.animateWithDuration(0.2, animations: { - self.textLabel.transform = CGAffineTransformMakeScale(1.0, 1.0) + iconImageView.transform = CGAffineTransform(scaleX: 0, y: 0) + textLabel.transform = CGAffineTransform(scaleX: 0, y: 0) + dotView.transform = CGAffineTransform(scaleX: 0, y: 0) + dotView.isHidden = false + UIView.animate(withDuration: 0.2, animations: { + self.textLabel.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) }) - UIView.animateWithDuration(0.2, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0, options: .CurveLinear, animations: { + UIView.animate(withDuration: 0.2, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0, options: .curveLinear, animations: { if self.iconImageView.image == nil { - self.dotView.transform = CGAffineTransformMakeScale(1.0, 1.0) + self.dotView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) } else { - self.iconImageView.transform = CGAffineTransformMakeScale(1.0, 1.0) + self.iconImageView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) } }, completion: nil) } @@ -489,20 +491,20 @@ public class YBButton : UIButton { fatalError("init(coder:) has not been implemented") } - override public func drawRect(rect: CGRect) { + override public func draw(_ rect: CGRect) { UIColor(white: 0.85, alpha: 1.0).setStroke() let line = UIBezierPath() line.lineWidth = 1 - line.moveToPoint(CGPoint(x: iconImageView.frame.maxX + 5, y: frame.height)) - line.addLineToPoint(CGPoint(x: frame.width , y: frame.height)) + line.move(to: CGPoint(x: iconImageView.frame.maxX + 5, y: frame.height)) + line.addLine(to: CGPoint(x: frame.width , y: frame.height)) line.stroke() } } class DotView:UIView { - var dotColor = UIColor.blackColor() + var dotColor = UIColor.black - override func drawRect(rect: CGRect) { + override func draw(_ rect: CGRect) { dotColor.setFill() let circle = UIBezierPath(arcCenter: CGPoint(x: frame.width/2, y: frame.height/2), radius: 3, startAngle: 0, endAngle: 360, clockwise: true) circle.fill() diff --git a/Example/Pods/Pods.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example/Pods/Pods.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/Example/Pods/Pods.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Example/Pods/Pods.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example/Pods/Pods.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Example/Pods/Pods.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 0200acad26e1635e0035253253e28e93ebaa964d Mon Sep 17 00:00:00 2001 From: Samuel Hyeman Date: Sun, 14 Jun 2020 18:17:34 +0100 Subject: [PATCH 2/3] changed dispatch time of the buttons --- Classes/YBAlertController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/YBAlertController.swift b/Classes/YBAlertController.swift index cf92e61..ed62515 100644 --- a/Classes/YBAlertController.swift +++ b/Classes/YBAlertController.swift @@ -357,7 +357,7 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { private func startButtonAppearAnimation() { for i in 0.. Date: Mon, 29 Jun 2020 19:03:18 +0100 Subject: [PATCH 3/3] reduced interval time of buttons --- Classes/YBAlertController.swift | 85 ++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/Classes/YBAlertController.swift b/Classes/YBAlertController.swift index ed62515..85cb1d2 100644 --- a/Classes/YBAlertController.swift +++ b/Classes/YBAlertController.swift @@ -75,12 +75,12 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { containerView.backgroundColor = UIColor.white containerView.clipsToBounds = true - let tapGesture = UITapGestureRecognizer(target: self, action: Selector(("dismiss"))) + let tapGesture = UITapGestureRecognizer(target: self, action: #selector((dismissView))) tapGesture.numberOfTapsRequired = 1 tapGesture.delegate = self self.view.addGestureRecognizer(tapGesture) - NotificationCenter.default.addObserver(self, selector: Selector(("changedOrientation:")), name: UIDevice.orientationDidChangeNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector((changedOrientation)), name: UIDevice.orientationDidChangeNotification, object: nil) } public convenience init(style: YBAlertControllerStyle) { @@ -99,7 +99,7 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { NotificationCenter.default.removeObserver(self) } - func changedOrientation(notification: NSNotification) { + @objc func changedOrientation(notification: NSNotification) { if showing && style == YBAlertControllerStyle.ActionSheet { let value = currentOrientation?.rawValue UIDevice.current.setValue(value, forKey: "orientation") @@ -133,7 +133,7 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { options: .curveEaseIn, animations: { self.containerView.frame.origin.y = self.view.frame.height - self.containerView.frame.height - self.getTopViewController()?.view.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) + // self.getTopViewController()?.view.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) }, completion: { (finished) in if self.animated { @@ -171,34 +171,7 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { } } - public func dismiss() { - showing = false - if let statusBarStyle = currentStatusBarStyle { - UIApplication.shared.statusBarStyle = statusBarStyle - } - - if style == .ActionSheet { - UIView.animate(withDuration: 0.2, - animations: { - self.containerView.frame.origin.y = self.view.frame.height - self.view.backgroundColor = UIColor(white: 0, alpha: 0) - self.getTopViewController()?.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) - }, - completion: { (finished) in - self.view.removeFromSuperview() - }) - } else { - UIView.animate(withDuration: 0.2, - animations: { - self.view.backgroundColor = UIColor(white: 0, alpha: 0) - self.containerView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5) - self.containerView.alpha = 0 - }, - completion: { (finished) in - self.view.removeFromSuperview() - }) - } - } + private func getTopViewController() -> UIViewController? { var topVC = UIApplication.shared.keyWindow?.rootViewController @@ -301,7 +274,7 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { cancelButton.titleLabel?.font = cancelButtonFont cancelButton.setTitle(cancelButtonTitle, for: .normal) cancelButton.setTitleColor(cancelButtonTextColor, for: .normal) - cancelButton.addTarget(self, action: Selector(("dismiss")), for: .touchUpInside) + cancelButton.addTarget(self, action: #selector((self.dismissView)), for: .touchUpInside) containerView.addSubview(cancelButton) posY += cancelButton.frame.height } @@ -312,7 +285,6 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { view.addSubview(containerView) - if style == YBAlertControllerStyle.ActionSheet { self.view.addConstraints([ NSLayoutConstraint(item: containerView, attribute: NSLayoutConstraint.Attribute.width, relatedBy: .equal, toItem: self.view, attribute: .width, multiplier: 1.0, constant: 0), @@ -365,6 +337,41 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { } } + @objc public func dismissView() { + showing = false + if let statusBarStyle = currentStatusBarStyle { + UIApplication.shared.statusBarStyle = statusBarStyle + } + + if style == .ActionSheet { + UIView.animate(withDuration: 0.2, + animations: { + self.containerView.frame.origin.y = self.view.frame.height + self.view.backgroundColor = UIColor(white: 0, alpha: 0) + self.getTopViewController()?.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) + }, + completion: { (finished) in + self.view.removeFromSuperview() + }) + } else { + UIView.animate(withDuration: 0.2, + animations: { + self.view.backgroundColor = UIColor(white: 0, alpha: 0) + self.containerView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5) + self.containerView.alpha = 0 + }, + completion: { (finished) in + self.view.removeFromSuperview() + }) + } + } + + + + + + + private func startCancelButtonAppearAnimation() { cancelButton.titleLabel?.transform = CGAffineTransform(scaleX: 0, y: 0) cancelButton.isHidden = false @@ -379,7 +386,7 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { button.action = action button.buttonColor = buttonIconColor button.buttonFont = buttonFont - button.addTarget(self, action: Selector(("buttonTapped:")), for: .touchUpInside) + button.addTarget(self, action: #selector((self.buttonTapped(button:))), for: .touchUpInside) buttons.append(button) } @@ -390,7 +397,7 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { button.target = target button.selector = selector button.buttonFont = buttonFont - button.addTarget(self, action: Selector(("buttonTapped:")), for: .touchUpInside) + button.addTarget(self, action: #selector((self.buttonTapped(button:))), for: .touchUpInside) buttons.append(button) } @@ -402,14 +409,14 @@ public class YBAlertController: UIViewController, UIGestureRecognizerDelegate { addButton(icon: nil, title: title, target: target, selector: selector) } - func buttonTapped(button:YBButton) { + @objc func buttonTapped(button:YBButton) { if button.actionType == YBButtonActionType.Closure { button.action() } else if button.actionType == YBButtonActionType.Selector { let control = UIControl() control.sendAction(button.selector, to: button.target, for: nil) } - dismiss() + dismissView() } } @@ -492,7 +499,7 @@ public class YBButton : UIButton { } override public func draw(_ rect: CGRect) { - UIColor(white: 0.85, alpha: 1.0).setStroke() + UIColor(white: 0.85, alpha: 0.7).setStroke() let line = UIBezierPath() line.lineWidth = 1 line.move(to: CGPoint(x: iconImageView.frame.maxX + 5, y: frame.height))