From 46fb386183582c02aaecd46dad3f75f010bceaa0 Mon Sep 17 00:00:00 2001 From: Tony Zaitoun Date: Sun, 16 Apr 2017 03:58:28 +0300 Subject: [PATCH] Added Podspec --- .DS_Store | Bin 8196 -> 8196 bytes AZDialogView.podspec | 11 ++++ AZDialogViewControllerExample/.DS_Store | Bin 8196 -> 8196 bytes .../AZDialogViewControllerExample/.DS_Store | Bin 6148 -> 6148 bytes .../ViewController.swift | 43 ++++++++----- Sources/AZDialogViewController.swift | 60 +++++++++++------- 6 files changed, 76 insertions(+), 38 deletions(-) create mode 100644 AZDialogView.podspec diff --git a/.DS_Store b/.DS_Store index 0fccec2ea43a72b23f49f2f83557d3fe60fc855b..54b7ef9a37dabcc06c16bf39e254d8e37794026f 100644 GIT binary patch delta 190 zcmZp1XmOa}&nUJrU^hRb*yIC(c9XpXQW;N7-XPGRAzoc=YO14PXklKfqfl*OVW6X6 zW?)=f%fTV8YG~`3kXu<*T~k{(WAZx@dB&L_&73L4$vH{+`8kY0-Vp)Moc!dZoctsP z1_l8J2FBLSaYCYuNNN~Gq$U>&ACo~-_Zg^O<3AWMFl<&AVFZHBnxYX*o7pA4u}m%( K*$C!`G64X7_dARL delta 102 zcmZp1XmOa}&nUbxU^hRb@Z|l1c9XpXQYW7hY2h$6GSpEpHZ`3bAnZ8#kf1eZN^x>d zQht6815nwK$vcJKPd+VtZ1R4Q_lyji*Na9lO>Ah}%r5bbWpcWpz~srI(s1Es06~`} A3jhEB diff --git a/AZDialogView.podspec b/AZDialogView.podspec new file mode 100644 index 0000000..b66e52e --- /dev/null +++ b/AZDialogView.podspec @@ -0,0 +1,11 @@ +Pod::Spec.new do |s| + s.name = "AZDialogView" + s.version = "1.0.0" + s.summary = "A highly customizable alert dialog controller that mimics Snapchat's alert dialog." + s.homepage = "https://github.com/Minitour/AZDialogViewController" + s.license = "MIT" + s.author = { "Antonio Zaitoun" => "tony.z.1711@gmail.com" } + s.platform = :ios, "9.0" + s.source = { :git => "https://github.com/Minitour/AZDialogViewController.git", :tag => "#{s.version}" } + s.source_files = "Sources/**/*.{swift}" +end diff --git a/AZDialogViewControllerExample/.DS_Store b/AZDialogViewControllerExample/.DS_Store index 20d90f98661b340555ab92d0c2828433e3580c49..1b59d6c2b1cd200bbc257d84f39d0638128efa9b 100644 GIT binary patch delta 80 zcmZp1XmQxUBFuJFmVtpmeX@Xn)npD45s}<{7nhXMl4J&kE4R0W0i}>6C+`yG=0q1& MViee{Epn3^07KLh@Bjb+ delta 80 zcmZp1XmQxUBFuKsk%56heX@Xn)npD45s}<{7nhXMl4J&kD>p^^fl^44lXnSobE1nX MF*0n{7P-j{057r=EC2ui diff --git a/AZDialogViewControllerExample/AZDialogViewControllerExample/.DS_Store b/AZDialogViewControllerExample/AZDialogViewControllerExample/.DS_Store index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..38eca971757cf654a6a40174a4870d9ce5da5215 100644 GIT binary patch delta 163 zcmZoMXfc=|&e%RNQEZ}~q9_vs0|O%ig8&0V2}3c19zz8~GDG6TM0H<~1V4i#P_URG z6W_At%4o20D55F@{<`+>E1WGX^ QfYbm1h~2Q+QRFZ)06)qPH2?qr diff --git a/AZDialogViewControllerExample/AZDialogViewControllerExample/ViewController.swift b/AZDialogViewControllerExample/AZDialogViewControllerExample/ViewController.swift index 75fa8ef..90aab32 100644 --- a/AZDialogViewControllerExample/AZDialogViewControllerExample/ViewController.swift +++ b/AZDialogViewControllerExample/AZDialogViewControllerExample/ViewController.swift @@ -83,7 +83,7 @@ class ViewController: UIViewController { print("Share function") } - dialogController.dismissDirection = .bottom + dialogController.dismissDirection = .both dialogController.dismissWithOutsideTouch = true @@ -91,7 +91,7 @@ class ViewController: UIViewController { } func editUserDialog(){ - let dialogController = AZDialogViewController(title: "Antonio Zaitoun", message: "minitour") + let dialogController = AZDialogViewController(title: "This is a very long string and I am really bored. whatever mate", message: "minitour") dialogController.showSeparator = true dialogController.addAction(AZDialogAction(title: "Edit Name", handler: { (dialog) -> (Void) in @@ -166,24 +166,32 @@ class ViewController: UIViewController { } func reportDialog(){ - let dialogController = AZDialogViewController(title: "Report Pack", message: "Please let us know the reason you are reporting this pack.",buttonsHeight: 35) + let dialogController = AZDialogViewController(title: nil, message: nil) dialogController.dismissDirection = .bottom dialogController.dismissWithOutsideTouch = true - let primary = #colorLiteral(red: 0, green: 0.8213806748, blue: 0.4752416015, alpha: 1) - let primaryDark = #colorLiteral(red: 0, green: 0.7293747497, blue: 0.4250124319, alpha: 1) + let primary = #colorLiteral(red: 0, green: 0.6862745098, blue: 0.9411764706, alpha: 1) + let primaryDark = #colorLiteral(red: 0.02745098039, green: 0.368627451, blue: 0.3294117647, alpha: 1) + dialogController.buttonStyle = { (button,height,position) in button.tintColor = primary - button.setTitleColor(.white, for: []) - //button.setTitleColor(primary, for: .normal) + button.layer.masksToBounds = true button.setBackgroundImage(UIImage.imageWithColor(primary) , for: .normal) - button.setBackgroundImage(UIImage.imageWithColor(primaryDark) , for: .highlighted) + button.setBackgroundImage(UIImage.imageWithColor(primaryDark), for: .highlighted) + button.setTitleColor(UIColor.white, for: []) button.layer.masksToBounds = true - button.layer.cornerRadius = 5 - - button.layer.borderWidth = 0 + button.layer.borderColor = self.primaryColor.cgColor + button.layer.borderColor = primary.cgColor + + if position == 4 { + button.setTitleColor(UIColor.white, for: .highlighted) + button.setBackgroundImage(UIImage.imageWithColor(#colorLiteral(red: 1, green: 0.3005838394, blue: 0.2565174997, alpha: 1)), for: .highlighted) + button.setBackgroundImage(nil , for: .normal) + button.setTitleColor(#colorLiteral(red: 1, green: 0.3005838394, blue: 0.2565174997, alpha: 1), for: .normal) + button.layer.borderColor = #colorLiteral(red: 1, green: 0.3005838394, blue: 0.2565174997, alpha: 1).cgColor + } } dialogController.cancelButtonStyle = { (button, height) in @@ -192,22 +200,27 @@ class ViewController: UIViewController { return true } - dialogController.addAction(AZDialogAction(title: "Not for me", handler: { (dialog) -> (Void) in + dialogController.addAction(AZDialogAction(title: "Mute", handler: { (dialog) -> (Void) in dialog.dismiss() })) - dialogController.addAction(AZDialogAction(title: "Spam", handler: { (dialog) -> (Void) in + dialogController.addAction(AZDialogAction(title: "Group Info", handler: { (dialog) -> (Void) in dialog.dismiss() })) - dialogController.addAction(AZDialogAction(title: "Offensive Content", handler: { (dialog) -> (Void) in + dialogController.addAction(AZDialogAction(title: "Export Chat", handler: { (dialog) -> (Void) in + dialog.dismiss() + })) + + dialogController.addAction(AZDialogAction(title: "Clear Chat", handler: { (dialog) -> (Void) in dialog.dismiss() })) - dialogController.addAction(AZDialogAction(title: "Other", handler: { (dialog) -> (Void) in + dialogController.addAction(AZDialogAction(title: "Exit Chat", handler: { (dialog) -> (Void) in dialog.dismiss() })) + dialogController.show(in: self) } } diff --git a/Sources/AZDialogViewController.swift b/Sources/AZDialogViewController.swift index 2fccd3c..be3d393 100644 --- a/Sources/AZDialogViewController.swift +++ b/Sources/AZDialogViewController.swift @@ -111,7 +111,7 @@ open class AZDialogViewController: UIViewController{ open override func dismiss(animated: Bool = true,completion: (()->Void)?=nil){ if animated { UIView.animate(withDuration: 0.2, animations: { () -> Void in - self.baseView.center.y = (self.baseView.superview?.frame.maxY)! + (self.baseView.frame.midY) + self.baseView.center.y = self.view.bounds.maxY + (self.baseView.bounds.midY) self.view.backgroundColor = .clear }, completion: { (complete) -> Void in super.dismiss(animated: false, completion: completion) @@ -348,7 +348,7 @@ open class AZDialogViewController: UIViewController{ super.viewDidAppear(animated) if !didInitAnimation{ didInitAnimation = true - baseView.center.y = (baseView.superview?.frame.maxY)! + (baseView.frame.midY) + baseView.center.y = self.view.bounds.maxY + baseView.bounds.midY baseView.isHidden = false UIView.animate(withDuration: 0.2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 6.0, options: [], animations: { () -> Void in self.baseView.center = (self.baseView.superview?.center)! @@ -396,6 +396,7 @@ open class AZDialogViewController: UIViewController{ fontName: String = "AvenirNext-Medium", boldFontName: String = "AvenirNext-DemiBold"){ self.init(nibName: nil, bundle: nil) + mTitle = title mMessage = message self.spacing = spacing @@ -418,29 +419,36 @@ open class AZDialogViewController: UIViewController{ let translation = sender.translation(in: self.view) baseView.center = CGPoint(x: baseView.lastLocation.x , y: baseView.lastLocation.y + translation.y) - if sender.state == UIGestureRecognizerState.ended{ + let returnToCenter:(CGPoint,Bool)->Void = { (finalPoint,animate) in + if !animate { + self.baseView.center = finalPoint + return + } + UIView.animate(withDuration: 0.35, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 2.0, options: [], animations: { () -> Void in + self.baseView.center = finalPoint + }, completion: { (complete) -> Void in + }) + } + + let dismissInDirection:(CGPoint)->Void = { (finalPoint) in + UIView.animate(withDuration: 0.2, animations: { () -> Void in + self.baseView.center = finalPoint + self.view.backgroundColor = .clear + }, completion: { (complete) -> Void in + self.dismiss(animated: false, completion: nil) + }) + } + + var finalPoint = (baseView.superview?.center)! + + if sender.state == .ended{ let velocity = sender.velocity(in: view) let mag = sqrtf(Float(velocity.x * velocity.x) + Float(velocity.y * velocity.y)) let slideMult = mag / 200 - var finalPoint = (baseView.superview?.center)! let dismissWithGesture = dismissDirection != .none ? true : false - let returnToCenter = { - UIView.animate(withDuration: 0.35, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 2.0, options: [], animations: { () -> Void in - self.baseView.center = finalPoint - }, completion: { (complete) -> Void in - }) - } - let dismissInDirection = { - UIView.animate(withDuration: 0.2, animations: { () -> Void in - self.baseView.center = finalPoint - self.view.backgroundColor = .clear - }, completion: { (complete) -> Void in - self.dismiss(animated: false, completion: nil) - }) - } if dismissWithGesture && slideMult > 1 { //dismiss @@ -448,25 +456,31 @@ open class AZDialogViewController: UIViewController{ //dismiss downward if dismissDirection == .bottom || dismissDirection == .both { finalPoint.y = (baseView.superview?.frame.maxY)! + (baseView.bounds.midY) - dismissInDirection() + dismissInDirection(finalPoint) }else{ - returnToCenter() + returnToCenter(finalPoint,true) } }else{ //dismiss upward if dismissDirection == .top || dismissDirection == .both { finalPoint.y = -(baseView.bounds.midY) - dismissInDirection() + dismissInDirection(finalPoint) }else{ - returnToCenter() + returnToCenter(finalPoint,true) } } }else{ //return to center - returnToCenter() + returnToCenter(finalPoint,true) } } + + if sender.state == .cancelled || sender.state == .failed{ + returnToCenter(finalPoint,false) + } + + } /// Selector method - used to handle view touch.