Skip to content

Commit

Permalink
fix UIGestureRecognizerDelegate conflict bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hongxinhope committed Mar 2, 2017
1 parent 08d1c0e commit 05c86b2
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 29 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ disabled_rules: # rule identifiers to exclude from running
- nesting
- variable_name_min_length
- cyclomatic_complexity
- class_delegate_protocol
included: # paths to include during linting. `--path` is ignored if present. takes precendence over `excluded`.
excluded: # paths to ignore during linting. overridden by `included`.
- Carthage
Expand Down
2 changes: 1 addition & 1 deletion Example/EmptyDataDemoCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class EmptyDataDemoCollectionViewController: UICollectionViewController {
self.dataCount -= 1
collectionView.performBatchUpdates({
self.collectionView?.deleteItems(at: [indexPath])
}) { (completed) in
}) { (_) in

}
}
Expand Down
4 changes: 2 additions & 2 deletions Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.4</string>
<string>2.5</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>15</string>
<string>16</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
2 changes: 1 addition & 1 deletion TBEmptyDataSet.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "TBEmptyDataSet"
s.version = "2.4"
s.version = "2.5"
s.summary = "An extension of UITableView/UICollectionView's super class, it will display a placeholder when the data is empty."

s.homepage = "https://github.com/teambition/TBEmptyDataSet"
Expand Down
6 changes: 3 additions & 3 deletions TBEmptyDataSet/EmptyDataView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ internal class EmptyDataView: UIView {
let centerY = NSLayoutConstraint(item: contentView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1, constant: verticalOffset)
addConstraint(centerX)
addConstraint(centerY)
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[\(ViewStrings.contentView)]|", options: [], metrics: nil, views: [ViewStrings.contentView : contentView]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[\(ViewStrings.contentView)]|", options: [], metrics: nil, views: [ViewStrings.contentView: contentView]))

if let customView = customView {
let translatesFrameIntoConstraints = customView.translatesAutoresizingMaskIntoConstraints
Expand Down Expand Up @@ -168,7 +168,7 @@ internal class EmptyDataView: UIView {
let viewString = ViewStrings.titleLabel
viewStrings.append(viewString)
views[viewString] = titleLabel
contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-[\(ViewStrings.titleLabel)(>=0)]-|", options: [], metrics: nil, views: [ViewStrings.titleLabel : titleLabel]))
contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-[\(ViewStrings.titleLabel)(>=0)]-|", options: [], metrics: nil, views: [ViewStrings.titleLabel: titleLabel]))
} else {
titleLabel.removeFromSuperview()
}
Expand All @@ -180,7 +180,7 @@ internal class EmptyDataView: UIView {
let viewString = ViewStrings.descriptionLabel
viewStrings.append(viewString)
views[viewString] = descriptionLabel
contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-[\(ViewStrings.descriptionLabel)(>=0)]-|", options: [], metrics: nil, views: [ViewStrings.descriptionLabel : descriptionLabel]))
contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-[\(ViewStrings.descriptionLabel)(>=0)]-|", options: [], metrics: nil, views: [ViewStrings.descriptionLabel: descriptionLabel]))
} else {
descriptionLabel.removeFromSuperview()
}
Expand Down
2 changes: 1 addition & 1 deletion TBEmptyDataSet/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.4</string>
<string>2.5</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
22 changes: 1 addition & 21 deletions TBEmptyDataSet/TBEmptyDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

extension UIScrollView: UIGestureRecognizerDelegate {
extension UIScrollView {
// MARK: - Properties
public var emptyDataSetDataSource: TBEmptyDataSetDataSource? {
get {
Expand Down Expand Up @@ -125,7 +125,6 @@ extension UIScrollView: UIGestureRecognizerDelegate {
emptyDataView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
emptyDataView.isHidden = true
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapEmptyDataView(_:)))
tapGesture.delegate = self
emptyDataView.addGestureRecognizer(tapGesture)
emptyDataView.tapGesture = tapGesture
return emptyDataView
Expand Down Expand Up @@ -174,21 +173,6 @@ extension UIScrollView: UIGestureRecognizerDelegate {
emptyDataSetDelegate?.emptyDataSetDidDisappear(in: self)
}

// MARK: - UIGestureRecognizer delegate
override open func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if gestureRecognizer.view is EmptyDataView {
return emptyDataSetTapEnabled()
}
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}

open func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
if let emptyDataView = emptyDataView, gestureRecognizer == emptyDataView.tapGesture || otherGestureRecognizer == emptyDataView.tapGesture {
return true
}
return false
}

// MARK: - Display
// swiftlint:disable function_body_length
fileprivate func reloadEmptyDataSet() {
Expand Down Expand Up @@ -273,7 +257,6 @@ extension UIScrollView: UIGestureRecognizerDelegate {
let swizzledSelector = Selectors.tableViewSwizzledReloadData

tb_swizzleMethod(for: UITableView.self, originalSelector: originalSelector, swizzledSelector: swizzledSelector)
print("tb_swizzleTableViewReloadData")
}()

// swiftlint:disable variable_name
Expand All @@ -282,7 +265,6 @@ extension UIScrollView: UIGestureRecognizerDelegate {
let swizzledSelector = Selectors.tableViewSwizzledEndUpdates

tb_swizzleMethod(for: UITableView.self, originalSelector: originalSelector, swizzledSelector: swizzledSelector)
print("tb_swizzleTableViewEndUpdates")
}()

// swiftlint:disable variable_name
Expand All @@ -291,7 +273,6 @@ extension UIScrollView: UIGestureRecognizerDelegate {
let swizzledSelector = Selectors.collectionViewSwizzledReloadData

tb_swizzleMethod(for: UICollectionView.self, originalSelector: originalSelector, swizzledSelector: swizzledSelector)
print("tb_swizzleCollectionViewReloadData")
}()

// swiftlint:disable variable_name
Expand All @@ -300,7 +281,6 @@ extension UIScrollView: UIGestureRecognizerDelegate {
let swizzledSelector = Selectors.collectionViewSwizzledPerformBatchUpdates

tb_swizzleMethod(for: UICollectionView.self, originalSelector: originalSelector, swizzledSelector: swizzledSelector)
print("tb_swizzleCollectionViewPerformBatchUpdates")
}()

func tb_tableViewSwizzledReloadData() {
Expand Down

0 comments on commit 05c86b2

Please sign in to comment.