Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemesisprime committed May 1, 2022
2 parents 5cfd698 + 5d8f507 commit e614f53
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
2 changes: 1 addition & 1 deletion MYTableViewIndex/Public/TableViewIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ open class TableViewIndex : UIControl {
let layout = ItemLayout(items: items, style: style)
let width = layout.size.width + style.indexInset.left + style.indexInset.right
let minWidth: CGFloat = 44.0
return CGSize(width: max(width, minWidth), height: UIViewNoIntrinsicMetric)
return CGSize(width: max(width, minWidth), height: UIView.noIntrinsicMetric)
}

open override func sizeThatFits(_ size: CGSize) -> CGSize {
Expand Down
14 changes: 7 additions & 7 deletions MYTableViewIndex/Public/TableViewIndexController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,27 @@ public class TableViewIndexController : NSObject {
// MARK: - Keyboard

private func observeKeyboard() {
NotificationCenter.default.addObserver(self, selector: #selector(TableViewIndexController.handleKeyboardNotification(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(TableViewIndexController.handleKeyboardNotification(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(TableViewIndexController.handleKeyboardNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(TableViewIndexController.handleKeyboardNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}

@objc private func handleKeyboardNotification(_ note: Notification) {
guard let scrollView = scrollView, let parentView = scrollView.superview, let userInfo = note.userInfo else {
return;
}

if let frame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,
let curve = (userInfo[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber)?.intValue,
let duration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue {
if let frame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,
let curve = (userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.intValue,
let duration = (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue {

let convertedFrame = parentView.convert(frame, from: nil)

var inset = scrollView.contentInset
inset.bottom = (scrollView.frame.maxY - convertedFrame.minY)

UIView.animate(withDuration: duration, animations: {
UIView.setAnimationCurve(UIViewAnimationCurve(rawValue: curve)!)
UIView.setAnimationCurve(UIView.AnimationCurve(rawValue: curve)!)

self.layout(with: inset)
parentView.layoutIfNeeded()
Expand Down
27 changes: 27 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// swift-tools-version: 5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "MYTableViewIndex",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "MYTableViewIndex",
targets: ["MYTableViewIndex"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "MYTableViewIndex",
path: "MYTableViewIndex",
publicHeadersPath: "."
)
]
)

0 comments on commit e614f53

Please sign in to comment.