Skip to content

Commit

Permalink
修复再次调用show(in:)方法位置不正确的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
DancewithPeng committed Jun 15, 2021
1 parent 2e9e6a8 commit f0405a1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion KBPopup.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "KBPopup"
spec.version = "1.0.1"
spec.version = "1.0.2"
spec.summary = "iOS带箭头的起泡弹窗"
spec.description = <<-DESC
iOS带箭头的起泡弹窗,使用于需要在页面内弹窗的场景
Expand Down
8 changes: 4 additions & 4 deletions KBPopup.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -581,14 +581,14 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = G6RN72YKHF;
DEVELOPMENT_TEAM = 9TH5FC22B7;
INFOPLIST_FILE = KBPopupExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = team.kuibu.iOS.KBPopupExample;
PRODUCT_BUNDLE_IDENTIFIER = team.kuibu.iOS.KBPopupExample.JL;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "KBPopupExample/KBPopupExample-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -605,14 +605,14 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = G6RN72YKHF;
DEVELOPMENT_TEAM = 9TH5FC22B7;
INFOPLIST_FILE = KBPopupExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = team.kuibu.iOS.KBPopupExample;
PRODUCT_BUNDLE_IDENTIFIER = team.kuibu.iOS.KBPopupExample.JL;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "KBPopupExample/KBPopupExample-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
16 changes: 12 additions & 4 deletions KBPopup/Sources/KBPopupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ open class KBPopupView: KBDecorationView {
@objc
private var arrowDirection: ArrowDirection = .down {
didSet {
invalidateIntrinsicContentSize()
setNeedsLayout()
}
}

Expand Down Expand Up @@ -259,8 +259,6 @@ extension KBPopupView {
@objc
public func show(in containerView: UIView) {
show(in: containerView) { popupView in

popupView.layer.opacity = 0;

// 默认显示动画
let animation = CABasicAnimation(keyPath: "opacity")
Expand All @@ -282,13 +280,22 @@ extension KBPopupView {
@objc
public func show(in containerView: UIView, animationSetup: ((KBPopupView) -> Void)?) {

let animated = (containerView != self.superview)
if animated {
self.layer.opacity = 0;
} else {
self.layer.opacity = 1;
}

addToContainer(containerView)

if self.superview == nil {
return
}

animationSetup?(self)
if animated {
animationSetup?(self)
}
}

/// 隐藏弹窗,采用默认隐藏动画
Expand Down Expand Up @@ -371,6 +378,7 @@ extension KBPopupView {
arrowVertexXOffset = sourceViewFrame.midX - (containerView.bounds.width - self.bounds.midX - margin.right)
positionX = containerView.bounds.width - margin.right - (bounds.width - arrowVertexPosition.x)
} else {
arrowVertexXOffset = 0
positionX = sourceViewFrame.midX
}

Expand Down
23 changes: 10 additions & 13 deletions KBPopupExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import KBPopup

class ViewController: UIViewController {

var popupView: KBPopupView?
lazy var popupView: KBPopupView = {
let myView = UIView(frame: .zero)
myView.backgroundColor = .red

let popupView = KBPopupView(contentView: myView)
popupView.contentSize = CGSize(width: 180, height: 66)
popupView.margin = UIEdgeInsets(top: 50, left: 50, bottom: 50, right: 50)
return popupView
}()

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -23,27 +31,16 @@ class ViewController: UIViewController {
return
}

let myView = UIView(frame: .zero)
myView.backgroundColor = .red

let popupView = KBPopupView(contentView: myView)
popupView.contentSize = CGSize(width: 180, height: 66)
// popupView.sourceView = button
if let buttonFrame = button.window?.convert(button.frame, from: button.superview) {
popupView.sourceFrame = buttonFrame
}
popupView.margin = UIEdgeInsets(top: 50, left: 50, bottom: 50, right: 50)

popupView.show(in: self.view)

self.popupView = popupView
}

@objc
func backgroundDidTap(_ sender: Any?) {
// self.dismiss(animated: true, completion: nil)
// self.popupView?.removeFromSuperview()
self.popupView?.hide()
self.popupView.hide()
}

func testPopupView() {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ iOS带箭头的起泡弹窗
`Podfile`文件中加入

```ruby
pod 'KBPopup', '~> 1.0.1'
pod 'KBPopup', '~> 1.0.2'
```


Expand Down

0 comments on commit f0405a1

Please sign in to comment.