Skip to content

Commit

Permalink
Added Podspec
Browse files Browse the repository at this point in the history
  • Loading branch information
Minitour committed Apr 16, 2017
1 parent 90999bf commit 46fb386
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 38 deletions.
Binary file modified .DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions AZDialogView.podspec
Original file line number Diff line number Diff line change
@@ -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" => "[email protected]" }
s.platform = :ios, "9.0"
s.source = { :git => "https://github.com/Minitour/AZDialogViewController.git", :tag => "#{s.version}" }
s.source_files = "Sources/**/*.{swift}"
end
Binary file modified AZDialogViewControllerExample/.DS_Store
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ class ViewController: UIViewController {
print("Share function")
}

dialogController.dismissDirection = .bottom
dialogController.dismissDirection = .both

dialogController.dismissWithOutsideTouch = true

dialogController.show(in: self)
}

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
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}
Expand Down
60 changes: 37 additions & 23 deletions Sources/AZDialogViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)!
Expand Down Expand Up @@ -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
Expand All @@ -418,55 +419,68 @@ 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
if velocity.y > 0{
//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.
Expand Down

0 comments on commit 46fb386

Please sign in to comment.