mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-24 20:26:02 +10:00
refactor isOperatingSystemAtLeastMajorVersion; workaround of longPress for menu or link
This commit is contained in:
@@ -78,3 +78,7 @@ func cleanRealmAndCaches() {
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(EditProfileViewController.Notification.Logout, object: nil)
|
||||
}
|
||||
|
||||
func isOperatingSystemAtLeastMajorVersion(majorVersion: Int) -> Bool {
|
||||
return NSProcessInfo().isOperatingSystemAtLeastVersion(NSOperatingSystemVersion(majorVersion: majorVersion, minorVersion: 0, patchVersion: 0))
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,20 @@ extension ChatLeftTextCell: UIGestureRecognizerDelegate {
|
||||
|
||||
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOfGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
|
||||
|
||||
return false
|
||||
// iOS 9 在长按链接时不弹出 menu
|
||||
|
||||
if isOperatingSystemAtLeastMajorVersion(9) {
|
||||
|
||||
if let longPressGestureRecognizer = otherGestureRecognizer as? UILongPressGestureRecognizer {
|
||||
if longPressGestureRecognizer.minimumPressDuration == 0.75 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,20 @@ extension ChatRightTextCell: UIGestureRecognizerDelegate {
|
||||
|
||||
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOfGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
|
||||
|
||||
return false
|
||||
// iOS 9 在长按链接时不弹出 menu
|
||||
|
||||
if isOperatingSystemAtLeastMajorVersion(9) {
|
||||
|
||||
if let longPressGestureRecognizer = otherGestureRecognizer as? UILongPressGestureRecognizer {
|
||||
if longPressGestureRecognizer.minimumPressDuration == 0.75 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,17 +10,19 @@ import UIKit
|
||||
|
||||
class ChatTextView: UITextView {
|
||||
|
||||
var menuLongPressGestureRecognizer: UILongPressGestureRecognizer!
|
||||
|
||||
override func canBecomeFirstResponder() -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
override func addGestureRecognizer(gestureRecognizer: UIGestureRecognizer) {
|
||||
|
||||
if NSProcessInfo().isOperatingSystemAtLeastVersion(NSOperatingSystemVersion(majorVersion: 9, minorVersion: 0, patchVersion: 0)) {
|
||||
// iOS 9 以上,强制不添加文字选择长按手势,免去触发选择文字
|
||||
// 共有四种长按手势,iOS 9 正式版里分别加了两次:0.1 Reveal,0.12 tap link,0.5 selection, 0.75 press link
|
||||
if isOperatingSystemAtLeastMajorVersion(9) {
|
||||
if let longPressGestureRecognizer = gestureRecognizer as? UILongPressGestureRecognizer {
|
||||
return
|
||||
if longPressGestureRecognizer.minimumPressDuration == 0.5 {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user