Skip to content

Commit

Permalink
1、稍微修改默认背景色;
Browse files Browse the repository at this point in the history
2、修改Sheet显示、隐藏动画;
  • Loading branch information
choiceyou committed May 2, 2018
1 parent 7dbbb75 commit 11e0e79
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 24 deletions.
1 change: 0 additions & 1 deletion FWPopupView/FWPopupView/FWDemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ extension FWDemoViewController {
print("点击了 FWDateView 的取消")
})
dateView.show()

break

default:
Expand Down
4 changes: 2 additions & 2 deletions FWPopupView/FWPopupView/FWPopupView/FWAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ open class FWAlertView: FWPopupView {
/// - detail: 描述
/// - confirmBlock: 确定按钮回调
/// - Returns: self
@objc open class func alert(title: String, detail: String, confirmBlock:@escaping FWPopupItemHandler) -> FWAlertView {
@objc open class func alert(title: String, detail: String, confirmBlock: FWPopupItemHandler? = nil) -> FWAlertView {

let alertView = FWAlertView()
let items = [FWPopupItem(title: alertView.property.defaultTextOK, itemType: .normal, isCancel: false, handler: confirmBlock)]
Expand All @@ -56,7 +56,7 @@ open class FWAlertView: FWPopupView {
/// - confirmBlock: 确定按钮回调
/// - cancelBlock: 取消按钮回调
/// - Returns: self
@objc open class func alert(title: String, detail: String, confirmBlock:@escaping FWPopupItemHandler, cancelBlock:@escaping FWPopupItemHandler) -> FWAlertView {
@objc open class func alert(title: String, detail: String, confirmBlock: FWPopupItemHandler? = nil, cancelBlock: FWPopupItemHandler? = nil) -> FWAlertView {

let alertView = FWAlertView()
let items = [FWPopupItem(title: alertView.property.defaultTextCancel, itemType: .normal, isCancel: true, handler: cancelBlock),
Expand Down
8 changes: 4 additions & 4 deletions FWPopupView/FWPopupView/FWPopupView/FWDateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ open class FWDateView: FWPopupView {
private var confirmBlock: FWDateViewConfirmBlock?
private var cancelBlock: FWPopupVoidBlock?

@objc open class func date(confirmBlock:@escaping FWDateViewConfirmBlock, cancelBlock:@escaping FWPopupVoidBlock) -> FWDateView {
@objc open class func date(confirmBlock: FWDateViewConfirmBlock? = nil, cancelBlock: FWPopupVoidBlock? = nil) -> FWDateView {

let dateView = FWDateView()
dateView.setupUI(confirmBlock: confirmBlock, cancelBlock: cancelBlock)
Expand All @@ -42,7 +42,7 @@ open class FWDateView: FWPopupView {

extension FWDateView {

private func setupUI(confirmBlock:@escaping FWDateViewConfirmBlock, cancelBlock:@escaping FWPopupVoidBlock) {
private func setupUI(confirmBlock: FWDateViewConfirmBlock? = nil, cancelBlock: FWPopupVoidBlock? = nil) {

self.backgroundColor = self.property.vbackgroundColor
self.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: self.property.datePickerHeight + self.property.btnHeight)
Expand Down Expand Up @@ -79,9 +79,9 @@ extension FWDateView {
@objc private func btnAction(_ sender: Any) {

let btn = sender as! UIButton
if btn.tag == 0 {
if btn.tag == 0 && self.cancelBlock != nil {
self.cancelBlock!()
} else {
} else if btn.tag == 1 && self.confirmBlock != nil {
self.confirmBlock!(self.datePicker)
}

Expand Down
2 changes: 1 addition & 1 deletion FWPopupView/FWPopupView/FWPopupView/FWPopupCategory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension UIView {
get {
let color = objc_getAssociatedObject(self, fwBackgroundViewColorKey) as? UIColor
guard color != nil else {
return UIColor(white: 0, alpha: 0.6)
return UIColor(white: 0, alpha: 0.5)
}
return color!
}
Expand Down
2 changes: 1 addition & 1 deletion FWPopupView/FWPopupView/FWPopupView/FWPopupItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ open class FWPopupItem: NSObject {

@objc open var itemHandler: FWPopupItemHandler?

@objc public init(title: String, itemType: FWItemType, isCancel: Bool, handler: @escaping FWPopupItemHandler) {
@objc public init(title: String, itemType: FWItemType, isCancel: Bool, handler: FWPopupItemHandler? = nil) {
self.title = title
self.itemType = itemType
self.isCancel = isCancel
Expand Down
31 changes: 21 additions & 10 deletions FWPopupView/FWPopupView/FWPopupView/FWPopupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import UIKit

/// 显示、隐藏回调
public typealias FWPopupBlock = (_ popupView: FWPopupView) -> Void
/// 显示、隐藏完成回调
/// 显示、隐藏完成回调,某些场景下可能会用到
public typealias FWPopupCompletionBlock = (_ popupView: FWPopupView, _ isCompletion: Bool) -> Void
/// 普通无参数回调
public typealias FWPopupVoidBlock = () -> Void
Expand Down Expand Up @@ -63,7 +63,7 @@ open class FWPopupView: UIView {
}
}

@objc public var animationDuration: TimeInterval = 0.3 {
@objc public var animationDuration: TimeInterval = 0.2 {
willSet {
self.attachedView?.fwAnimationDuration = newValue
}
Expand Down Expand Up @@ -115,7 +115,7 @@ extension FWPopupView {
}
}

@objc open func show(completionBlock:@escaping FWPopupCompletionBlock) {
@objc open func show(completionBlock: FWPopupCompletionBlock? = nil) {

self.showCompletionBlock = completionBlock

Expand All @@ -138,7 +138,7 @@ extension FWPopupView {
}
}

@objc open func hide(completionBlock:@escaping FWPopupCompletionBlock) {
@objc open func hide(completionBlock: FWPopupCompletionBlock? = nil) {

self.hideCompletionBlock = completionBlock

Expand All @@ -152,7 +152,9 @@ extension FWPopupView {
}

let hideAnimation = self.hideAnimation
hideAnimation!(self)
if hideAnimation != nil {
hideAnimation!(self)
}
}

@objc open class func hideAll() {
Expand All @@ -165,6 +167,13 @@ extension FWPopupView {
self.hide()
}
}

/// 弹窗是否隐藏
///
/// - Returns: 是否隐藏
@objc open class func isPopupViewHiden() -> Bool {
return FWPopupWindow.sharedInstance.isHidden
}
}

// MARK: - 动画事件
Expand Down Expand Up @@ -240,12 +249,13 @@ extension FWPopupView {
}
if strongSelf.superview == nil {
strongSelf.attachedView?.fwBackgroundView.addSubview(strongSelf)
strongSelf.frame.origin.y = UIScreen.main.bounds.height - strongSelf.frame.height
strongSelf.layoutIfNeeded()
strongSelf.frame.origin.y = UIScreen.main.bounds.height
}

UIView.animate(withDuration: strongSelf.animationDuration, delay: 0.0, options: [.curveEaseOut, .beginFromCurrentState], animations: {
UIView.animate(withDuration: strongSelf.animationDuration / 2, delay: 0.0, options: [.curveEaseOut, .beginFromCurrentState], animations: {

strongSelf.frame.origin.y = UIScreen.main.bounds.height - strongSelf.frame.height
strongSelf.layoutIfNeeded()
strongSelf.superview?.layoutIfNeeded()

}, completion: { (finished) in
Expand All @@ -267,8 +277,9 @@ extension FWPopupView {
guard let strongSelf = self else {
return
}
UIView.animate(withDuration: strongSelf.animationDuration, delay: 0.0, options: [.curveEaseIn, .beginFromCurrentState], animations: {
UIView.animate(withDuration: strongSelf.animationDuration / 2, delay: 0.0, options: [.curveEaseIn, .beginFromCurrentState], animations: {

strongSelf.frame.origin.y = UIScreen.main.bounds.height
strongSelf.superview?.layoutIfNeeded()

}, completion: { (finished) in
Expand Down Expand Up @@ -358,7 +369,7 @@ extension FWPopupView {
}


// MARK: - FWSheetView的相关属性
// MARK: - 弹窗的的相关配置属性
open class FWPopupViewProperty: NSObject {

// 单个点击按钮的高度
Expand Down
14 changes: 9 additions & 5 deletions FWPopupView/FWPopupView/FWPopupView/FWSheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ open class FWSheetView: FWPopupView {
/// - itemBlock: 点击回调
/// - cancenlBlock: 取消按钮回调
/// - Returns: self
@objc open class func sheet(title: String?, itemTitles: [String], itemBlock:@escaping FWPopupItemHandler, cancenlBlock:@escaping FWPopupVoidBlock) -> FWSheetView {
@objc open class func sheet(title: String?, itemTitles: [String], itemBlock: FWPopupItemHandler? = nil, cancenlBlock: FWPopupVoidBlock? = nil) -> FWSheetView {

let sheetView = FWSheetView()
sheetView.setupUI(title: title, itemTitles: itemTitles, itemBlock:itemBlock, cancenlBlock: cancenlBlock)
Expand All @@ -43,7 +43,7 @@ open class FWSheetView: FWPopupView {
/// - cancenlBlock: 取消按钮回调
/// - property: FWSheetView的相关属性
/// - Returns: self
@objc open class func sheet(title: String?, itemTitles: [String], itemBlock:@escaping FWPopupItemHandler, cancenlBlock:@escaping FWPopupVoidBlock, property: FWSheetViewProperty?) -> FWSheetView {
@objc open class func sheet(title: String?, itemTitles: [String], itemBlock: FWPopupItemHandler? = nil, cancenlBlock: FWPopupVoidBlock? = nil, property: FWSheetViewProperty?) -> FWSheetView {

let sheetView = FWSheetView()
if property != nil {
Expand All @@ -56,7 +56,7 @@ open class FWSheetView: FWPopupView {

extension FWSheetView {

private func setupUI(title: String?, itemTitles: [String], itemBlock:@escaping FWPopupItemHandler, cancenlBlock:@escaping FWPopupVoidBlock) {
private func setupUI(title: String?, itemTitles: [String], itemBlock: FWPopupItemHandler? = nil, cancenlBlock: FWPopupVoidBlock? = nil) {

if itemTitles.count == 0 {
return
Expand All @@ -69,7 +69,9 @@ extension FWSheetView {
self.animationDuration = 0.3

let itemClickBlock: FWPopupItemHandler = { (index) in
itemBlock(index)
if itemBlock != nil {
itemBlock!(index)
}
}
for title in itemTitles {
self.actionItemArray.append(FWPopupItem(title: title, itemType: .normal, isCancel: true, handler: itemClickBlock))
Expand Down Expand Up @@ -116,7 +118,9 @@ extension FWSheetView {
currentMaxY = btnContrainerView.frame.maxY

let block: FWPopupItemHandler = { (index) in
cancenlBlock()
if cancenlBlock != nil {
cancenlBlock!()
}
}

var tmpIndex = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

0 comments on commit 11e0e79

Please sign in to comment.