Skip to content

Commit 8b18cea

Browse files
committed
解决UITableView中点击不灵敏的问题
1 parent 8c9d5b4 commit 8b18cea

File tree

7 files changed

+48
-29
lines changed

7 files changed

+48
-29
lines changed

AttributedString.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "AttributedString"
4-
s.version = "2.1.0"
4+
s.version = "2.2.0"
55
s.summary = "基于Swift字符串插值快速构建你想要的富文本, 支持点击按住等事件获取, 支持多种类型过滤"
66

77
s.homepage = "https://github.com/lixiang1994/AttributedString"

AttributedString.xcodeproj/project.pbxproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@
838838
"@executable_path/Frameworks",
839839
"@loader_path/Frameworks",
840840
);
841-
MARKETING_VERSION = 2.0.0;
841+
MARKETING_VERSION = 2.2.0;
842842
PRODUCT_BUNDLE_IDENTIFIER = com.attributedstring.watchos;
843843
PRODUCT_NAME = AttributedString;
844844
SDKROOT = watchos;
@@ -866,7 +866,7 @@
866866
"@executable_path/Frameworks",
867867
"@loader_path/Frameworks",
868868
);
869-
MARKETING_VERSION = 2.0.0;
869+
MARKETING_VERSION = 2.2.0;
870870
PRODUCT_BUNDLE_IDENTIFIER = com.attributedstring.watchos;
871871
PRODUCT_NAME = AttributedString;
872872
SDKROOT = watchos;
@@ -893,7 +893,7 @@
893893
"@executable_path/Frameworks",
894894
"@loader_path/Frameworks",
895895
);
896-
MARKETING_VERSION = 2.0.0;
896+
MARKETING_VERSION = 2.2.0;
897897
PRODUCT_BUNDLE_IDENTIFIER = com.attributedstring.tvos;
898898
PRODUCT_NAME = AttributedString;
899899
SDKROOT = appletvos;
@@ -920,7 +920,7 @@
920920
"@executable_path/Frameworks",
921921
"@loader_path/Frameworks",
922922
);
923-
MARKETING_VERSION = 2.0.0;
923+
MARKETING_VERSION = 2.2.0;
924924
PRODUCT_BUNDLE_IDENTIFIER = com.attributedstring.tvos;
925925
PRODUCT_NAME = AttributedString;
926926
SDKROOT = appletvos;
@@ -996,7 +996,7 @@
996996
"@loader_path/Frameworks",
997997
);
998998
MACOSX_DEPLOYMENT_TARGET = 10.13;
999-
MARKETING_VERSION = 2.0.0;
999+
MARKETING_VERSION = 2.2.0;
10001000
PRODUCT_BUNDLE_IDENTIFIER = com.lee.attributedstring.macos;
10011001
PRODUCT_NAME = AttributedString;
10021002
SDKROOT = macosx;
@@ -1023,7 +1023,7 @@
10231023
"@loader_path/Frameworks",
10241024
);
10251025
MACOSX_DEPLOYMENT_TARGET = 10.13;
1026-
MARKETING_VERSION = 2.0.0;
1026+
MARKETING_VERSION = 2.2.0;
10271027
PRODUCT_BUNDLE_IDENTIFIER = com.lee.attributedstring.macos;
10281028
PRODUCT_NAME = AttributedString;
10291029
SDKROOT = macosx;
@@ -1170,7 +1170,7 @@
11701170
"@executable_path/Frameworks",
11711171
"@loader_path/Frameworks",
11721172
);
1173-
MARKETING_VERSION = 2.0.0;
1173+
MARKETING_VERSION = 2.2.0;
11741174
PRODUCT_BUNDLE_IDENTIFIER = com.lee.attributedstring.ios;
11751175
PRODUCT_NAME = AttributedString;
11761176
SKIP_INSTALL = YES;
@@ -1199,7 +1199,7 @@
11991199
"@executable_path/Frameworks",
12001200
"@loader_path/Frameworks",
12011201
);
1202-
MARKETING_VERSION = 2.0.0;
1202+
MARKETING_VERSION = 2.2.0;
12031203
PRODUCT_BUNDLE_IDENTIFIER = com.lee.attributedstring.ios;
12041204
PRODUCT_NAME = AttributedString;
12051205
SKIP_INSTALL = YES;

README_CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![Logo](Resources/logo.png)
22

3-
AttributedString - 基于Swift插值方式优雅的构建富文本
3+
# AttributedString - 基于Swift插值方式优雅的构建富文本
44

55
[![License](https://img.shields.io/cocoapods/l/AttributedString.svg)](LICENSE) 
66
![Swift](https://img.shields.io/badge/Swift-5.2-orange.svg) 

Sources/Action.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,16 @@ extension ASAttributedString.Action.Trigger {
232232
switch self {
233233
#if os(iOS)
234234
case .click where gesture is UITapGestureRecognizer:
235-
return gesture.state == .ended
235+
return true
236236
case .press where gesture is UILongPressGestureRecognizer:
237-
return gesture.state == .began
237+
return true
238238
#endif
239239

240240
#if os(macOS)
241241
case .click where gesture is NSClickGestureRecognizer:
242-
return gesture.state == .ended
242+
return true
243243
case .press where gesture is NSPressGestureRecognizer:
244-
return gesture.state == .began
244+
return true
245245
#endif
246246
default:
247247
return false

Sources/Extension/AppKit/NSTextFieldExtension.swift

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ fileprivate extension NSTextField {
248248

249249
@objc
250250
func attributedAction(_ sender: NSGestureRecognizer) {
251+
guard sender.state == .ended else { return }
251252
guard isActionEnabled else { return }
252253
guard let action = touched?.2 else { return }
253254
guard action.trigger.matching(sender) else { return }

Sources/Extension/UIKit/UILabel/UILabelExtension.swift

+16-7
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,12 @@ extension UILabel {
247247
super.touchesEnded(touches, with: event)
248248
return
249249
}
250-
self.touched = nil
251-
attributedText = touched.0.value
250+
// 保证delaysContentTouches时 touchesBegan -> Action -> touchesEnded的调用顺序
251+
DispatchQueue.main.async { [weak self] in
252+
guard let self = self else { return }
253+
self.touched = nil
254+
self.attributedText = touched.0.value
255+
}
252256
}
253257

254258
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
@@ -267,11 +271,16 @@ fileprivate extension UILabel {
267271

268272
@objc
269273
func attributedAction(_ sender: UIGestureRecognizer) {
270-
guard isActionEnabled else { return }
271-
guard let action = touched?.2 else { return }
272-
guard action.trigger.matching(sender) else { return }
273-
// 点击 回调
274-
action.handle?()
274+
guard sender.state == .ended else { return }
275+
// 保证delaysContentTouches时 touchesBegan -> Action -> touchesEnded的调用顺序
276+
DispatchQueue.main.async { [weak self] in
277+
guard let self = self else { return }
278+
guard self.isActionEnabled else { return }
279+
guard let action = self.touched?.2 else { return }
280+
guard action.trigger.matching(sender) else { return }
281+
// 点击 回调
282+
action.handle?()
283+
}
275284
}
276285

277286
func matching(_ point: CGPoint) -> (NSRange, Action)? {

Sources/Extension/UIKit/UITextViewExtension.swift

+17-8
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,13 @@ extension UITextView {
282282
super.touchesEnded(touches, with: event)
283283
return
284284
}
285-
self.touched = nil
286-
attributedText = touched.0.value
287-
layout()
285+
// 保证delaysContentTouches时 touchesBegan -> Action -> touchesEnded的调用顺序
286+
DispatchQueue.main.async { [weak self] in
287+
guard let self = self else { return }
288+
self.touched = nil
289+
self.attributedText = touched.0.value
290+
self.layout()
291+
}
288292
}
289293

290294
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
@@ -304,11 +308,16 @@ fileprivate extension UITextView {
304308

305309
@objc
306310
func attributedAction(_ sender: UIGestureRecognizer) {
307-
guard isActionEnabled else { return }
308-
guard let action = touched?.2 else { return }
309-
guard action.trigger.matching(sender) else { return }
310-
// 点击 回调
311-
action.handle?()
311+
guard sender.state == .ended else { return }
312+
// 保证delaysContentTouches时 touchesBegan -> Action -> touchesEnded的调用顺序
313+
DispatchQueue.main.async { [weak self] in
314+
guard let self = self else { return }
315+
guard self.isActionEnabled else { return }
316+
guard let action = self.touched?.2 else { return }
317+
guard action.trigger.matching(sender) else { return }
318+
// 点击 回调
319+
action.handle?()
320+
}
312321
}
313322

314323
func matching(_ point: CGPoint) -> (NSRange, Action)? {

0 commit comments

Comments
 (0)