Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion PTPopupWebView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "PTPopupWebView"
s.version = "0.4.0"
s.version = "0.4.2"
s.summary = "Swift subclass of the UIView which provide Popup web view."
s.homepage = "https://github.com/pjocprac/PTPopupWebView.git"
s.license = 'MIT'
Expand Down
38 changes: 19 additions & 19 deletions Pod/Classes/PTPopupWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ open class PTPopupWebView : UIView {
for buttonSetting in buttonSettings {
let button = UIButton()
button.titleLabel?.font = buttonSetting.font ?? style.buttonFont
button.setTitle(buttonSetting.title, for: UIControlState())
button.setTitleColor(buttonSetting.foregroundColor ?? style.buttonForegroundColor, for: UIControlState())
button.setTitle(buttonSetting.title, for: UIControl.State())
button.setTitleColor(buttonSetting.foregroundColor ?? style.buttonForegroundColor, for: UIControl.State())
button.setTitleColor(buttonSetting.disabledColor ?? style.buttonDisabledColor, for: .disabled)
button.backgroundColor = buttonSetting.backgroundColor ?? style.buttonBackgroundColor
button.setImage(buttonSetting.image, for: UIControlState())
button.setImage(buttonSetting.image, for: UIControl.State())

// Forward/Back/Reload's initial state is disabled
switch buttonSetting.type {
Expand All @@ -271,29 +271,29 @@ open class PTPopupWebView : UIView {
for i in 0 ..< buttons.count {
let button = buttons[i]
// Top/Bottom to container is 0
for attribute in [NSLayoutAttribute.top, NSLayoutAttribute.bottom] {
for attribute in [NSLayoutConstraint.Attribute.top, NSLayoutConstraint.Attribute.bottom] {
buttonContainer.addConstraint(
NSLayoutConstraint(
item : button, attribute: attribute, relatedBy: NSLayoutRelation.equal,
item : button, attribute: attribute, relatedBy: NSLayoutConstraint.Relation.equal,
toItem: buttonContainer, attribute: attribute, multiplier: 1.0, constant: 0.0)
)
}

// Leading constraint
let leftItem = i == 0 ? buttonContainer : buttons[i - 1]
let leftAttribute = i == 0 ? NSLayoutAttribute.leading : NSLayoutAttribute.trailing
let leftAttribute = i == 0 ? NSLayoutConstraint.Attribute.leading : NSLayoutConstraint.Attribute.trailing
buttonContainer.addConstraint(
NSLayoutConstraint(
item : button, attribute: NSLayoutAttribute.leading, relatedBy: NSLayoutRelation.equal,
item : button, attribute: NSLayoutConstraint.Attribute.leading, relatedBy: NSLayoutConstraint.Relation.equal,
toItem: leftItem, attribute: leftAttribute, multiplier: 1.0, constant: 0.0)
)

// Trailing constraint
let rightItem = i == buttons.count - 1 ? buttonContainer : buttons[i + 1]
let rightAttribute = i == buttons.count - 1 ? NSLayoutAttribute.trailing : NSLayoutAttribute.leading
let rightAttribute = i == buttons.count - 1 ? NSLayoutConstraint.Attribute.trailing : NSLayoutConstraint.Attribute.leading
buttonContainer.addConstraint(
NSLayoutConstraint(
item : button, attribute: NSLayoutAttribute.trailing, relatedBy: NSLayoutRelation.equal,
item : button, attribute: NSLayoutConstraint.Attribute.trailing, relatedBy: NSLayoutConstraint.Relation.equal,
toItem: rightItem, attribute: rightAttribute, multiplier: 1.0, constant: 0.0)
)
}
Expand All @@ -304,8 +304,8 @@ open class PTPopupWebView : UIView {
for i in 1 ..< buttons.count {
buttonContainer.addConstraint(
NSLayoutConstraint(
item : buttons[0], attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal,
toItem: buttons[i], attribute: NSLayoutAttribute.width, multiplier: 1.0, constant: 0.0)
item : buttons[0], attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal,
toItem: buttons[i], attribute: NSLayoutConstraint.Attribute.width, multiplier: 1.0, constant: 0.0)
)
}

Expand All @@ -316,8 +316,8 @@ open class PTPopupWebView : UIView {
let diffWidth = baseWidth - calcContentWidth(buttons[i])
buttonContainer.addConstraint(
NSLayoutConstraint(
item : buttons[0], attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal,
toItem: buttons[i], attribute: NSLayoutAttribute.width, multiplier: 1.0, constant: diffWidth)
item : buttons[0], attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal,
toItem: buttons[i], attribute: NSLayoutConstraint.Attribute.width, multiplier: 1.0, constant: diffWidth)
)
}
}
Expand All @@ -328,18 +328,18 @@ open class PTPopupWebView : UIView {
let bundle = Bundle(for: PTPopupWebViewButton.self)
let image = UIImage(named: "close", in: bundle, compatibleWith: nil)?.withRenderingMode(.alwaysTemplate)

closeButton.setImage(image, for: UIControlState())
closeButton.contentEdgeInsets = UIEdgeInsetsMake(8, 8, 8, 8)
closeButton.setImage(image, for: UIControl.State())
closeButton.contentEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
closeButton.addTarget(self, action: #selector(PTPopupWebView.close), for: .touchUpInside)
}

// Web view
webView.translatesAutoresizingMaskIntoConstraints = false
webViewContainer.addSubview(webView)
for attribute in [NSLayoutAttribute.top, NSLayoutAttribute.leading, NSLayoutAttribute.bottom, NSLayoutAttribute.trailing] {
for attribute in [NSLayoutConstraint.Attribute.top, NSLayoutConstraint.Attribute.leading, NSLayoutConstraint.Attribute.bottom, NSLayoutConstraint.Attribute.trailing] {
webViewContainer.addConstraint(
NSLayoutConstraint(
item : webViewContainer, attribute: attribute, relatedBy: NSLayoutRelation.equal,
item : webViewContainer, attribute: attribute, relatedBy: NSLayoutConstraint.Relation.equal,
toItem: webView, attribute: attribute, multiplier: 1.0, constant: 0.0)
)
}
Expand Down Expand Up @@ -469,7 +469,7 @@ open class PTPopupWebView : UIView {
}

/// Close popup view
open func close() {
@objc open func close() {
if let delegate = delegate {
// if delegate != nil (ex. when use PTPopupWebViewContoller)
delegate.close()
Expand All @@ -481,7 +481,7 @@ open class PTPopupWebView : UIView {
}


internal func buttonTapped (_ sender: AnyObject) {
@objc internal func buttonTapped (_ sender: AnyObject) {
if let button = sender as? UIButton, let index = buttons.index(of: button) {
if index < buttonSettings.count {
let buttonSetting = buttonSettings[index]
Expand Down
42 changes: 21 additions & 21 deletions Pod/Classes/PTPopupWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import WebKit
open class PTPopupWebViewController : UIViewController {
public enum PTPopupWebViewControllerBackgroundStyle {
// blur effect background
case blurEffect (UIBlurEffectStyle)
case blurEffect (UIBlurEffect.Style)
// opacity background
case opacity (UIColor?)
// transparent background
Expand Down Expand Up @@ -56,13 +56,13 @@ open class PTPopupWebViewController : UIViewController {
open fileprivate(set) var popupDisappearStyle : PTPopupWebViewControllerTransitionStyle = .pop(0.3, true)

fileprivate let attributes = [
NSLayoutAttribute.top,
NSLayoutAttribute.left,
NSLayoutAttribute.bottom,
NSLayoutAttribute.right
NSLayoutConstraint.Attribute.top,
NSLayoutConstraint.Attribute.left,
NSLayoutConstraint.Attribute.bottom,
NSLayoutConstraint.Attribute.right
]

fileprivate var constraints : [NSLayoutAttribute : NSLayoutConstraint] = [:]
fileprivate var constraints : [NSLayoutConstraint.Attribute : NSLayoutConstraint] = [:]

override open func loadView() {
let bundle = Bundle(for: type(of: self))
Expand Down Expand Up @@ -97,7 +97,7 @@ open class PTPopupWebViewController : UIViewController {
popupView.translatesAutoresizingMaskIntoConstraints = false
for attribute in attributes {
let constraint = NSLayoutConstraint(
item : contentView, attribute: attribute, relatedBy: NSLayoutRelation.equal,
item : contentView, attribute: attribute, relatedBy: NSLayoutConstraint.Relation.equal,
toItem: popupView, attribute: attribute, multiplier: 1.0, constant: 0.0)
contentView.addConstraint(constraint)
constraints[attribute] = constraint
Expand All @@ -121,7 +121,7 @@ open class PTPopupWebViewController : UIViewController {
break

case .fade (let duration):
UIView.animate(withDuration: duration, delay: 0, options: UIViewAnimationOptions(), animations: {self.popupView.alpha = 1}, completion: nil)
UIView.animate(withDuration: duration, delay: 0, options: UIView.AnimationOptions(), animations: {self.popupView.alpha = 1}, completion: nil)

case .slide(let direction, let duration, let damping):
self.popupView.alpha = 1
Expand All @@ -135,10 +135,10 @@ open class PTPopupWebViewController : UIViewController {
self.popupView.transform = CGAffineTransform(translationX: 0, y: 0)
}
if damping {
UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 0.75, initialSpringVelocity: 0, options: UIViewAnimationOptions(), animations: animations, completion: nil)
UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 0.75, initialSpringVelocity: 0, options: UIView.AnimationOptions(), animations: animations, completion: nil)
}
else {
UIView.animate(withDuration: duration, delay: 0, options: UIViewAnimationOptions(), animations: animations, completion: nil)
UIView.animate(withDuration: duration, delay: 0, options: UIView.AnimationOptions(), animations: animations, completion: nil)
}

case .spread (let duration):
Expand All @@ -148,7 +148,7 @@ open class PTPopupWebViewController : UIViewController {
CATransaction.setCompletionBlock({
self.popupView.layer.mask = nil
})
CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut))
CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut))

let maskLayer = CALayer()
maskLayer.backgroundColor = UIColor.white.cgColor
Expand Down Expand Up @@ -176,10 +176,10 @@ open class PTPopupWebViewController : UIViewController {
}

if damping {
UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 0.75, initialSpringVelocity: 0, options: UIViewAnimationOptions(), animations: animations, completion: nil)
UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 0.75, initialSpringVelocity: 0, options: UIView.AnimationOptions(), animations: animations, completion: nil)
}
else {
UIView.animate(withDuration: duration, delay: 0, options: UIViewAnimationOptions(), animations: animations, completion: nil)
UIView.animate(withDuration: duration, delay: 0, options: UIView.AnimationOptions(), animations: animations, completion: nil)
}
}
}
Expand Down Expand Up @@ -273,7 +273,7 @@ extension PTPopupWebViewController : PTPopupWebViewDelegate {
completion(true)

case .fade (let duration):
UIView.animate(withDuration: duration, delay: 0, options: UIViewAnimationOptions(), animations: {self.popupView.alpha = 0}, completion: completion)
UIView.animate(withDuration: duration, delay: 0, options: UIView.AnimationOptions(), animations: {self.popupView.alpha = 0}, completion: completion)

case .slide(let direction, let duration, let damping):
let animations = {
Expand All @@ -294,25 +294,25 @@ extension PTPopupWebViewController : PTPopupWebViewDelegate {
}
}
UIView.animate(
withDuration: duration/3, delay: 0, options: UIViewAnimationOptions(),
withDuration: duration/3, delay: 0, options: UIView.AnimationOptions(),
animations: springAnimations,
completion: { completed in
UIView.animate(
withDuration: duration * 2/3, delay: 0, options: UIViewAnimationOptions(),
withDuration: duration * 2/3, delay: 0, options: UIView.AnimationOptions(),
animations: animations,
completion: completion)
})
}
else {
UIView.animate(withDuration: duration, delay: 0, options: UIViewAnimationOptions(), animations: animations, completion: nil)
UIView.animate(withDuration: duration, delay: 0, options: UIView.AnimationOptions(), animations: animations, completion: nil)
}

case .spread (let duration):
CATransaction.begin()
CATransaction.setCompletionBlock({
completion(true)
})
CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut))
CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut))

let maskLayer = CALayer()
maskLayer.backgroundColor = UIColor.white.cgColor
Expand All @@ -336,21 +336,21 @@ extension PTPopupWebViewController : PTPopupWebViewDelegate {
case .pop (let duration, let damping):
if damping {
UIView.animate(
withDuration: duration/3, delay: 0, options: UIViewAnimationOptions(),
withDuration: duration/3, delay: 0, options: UIView.AnimationOptions(),
animations: {
self.popupView.transform = CGAffineTransform(scaleX: 1.05, y: 1.05)
},
completion: { completed in
UIView.animate(
withDuration: duration * 2/3, delay: 0, options: UIViewAnimationOptions(),
withDuration: duration * 2/3, delay: 0, options: UIView.AnimationOptions(),
animations: {
self.popupView.transform = CGAffineTransform(scaleX: 0.0000001, y: 0.0000001) // if 0, no animation
}, completion: completion)
})
}
else {
UIView.animate(
withDuration: duration, delay: 0, options: UIViewAnimationOptions(),
withDuration: duration, delay: 0, options: UIView.AnimationOptions(),
animations: {
self.popupView.transform = CGAffineTransform(scaleX: 0.0000001, y: 0.0000001)
}, completion: completion)
Expand Down
2 changes: 1 addition & 1 deletion Pod/Classes/PTPopupWebViewStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,6 @@ open class PTPopupWebViewControllerStyle : PTPopupWebViewStyle {
let screenBounds = UIScreen.main.bounds
let vMargin = screenBounds.height * 0.1
let hMargin = screenBounds.width * 0.05
outerMargin = UIEdgeInsetsMake(vMargin, hMargin, vMargin, hMargin)
outerMargin = UIEdgeInsets(top: vMargin, left: hMargin, bottom: vMargin, right: hMargin)
}
}