Skip to content

Commit f409a1c

Browse files
committed
Merge pull request #24 from cemolcay/feature/cemolcay-padding-press
Add hitTestEdgeInsets to KeyboardRow and KeyboardButton
2 parents bdc4115 + d294bd8 commit f409a1c

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

Keyboard/KeyboardLayoutEngine/KeyboardButton.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public class KeyboardButton: UIView {
101101
public var textLabel: UILabel?
102102
public var imageView: UIImageView?
103103

104+
public var hitTestEdgeInsets: UIEdgeInsets = UIEdgeInsets(top: -6, left: -6, bottom: -6, right: -6)
105+
104106
public var identifier: String?
105107
public var highlighted: Bool = false {
106108
didSet {
@@ -288,4 +290,14 @@ public class KeyboardButton: UIView {
288290

289291
return contentView
290292
}
293+
294+
// MARK: Hit Test
295+
public override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
296+
if UIEdgeInsetsEqualToEdgeInsets(hitTestEdgeInsets, UIEdgeInsetsZero) {
297+
return super.pointInside(point, withEvent: event)
298+
}
299+
300+
let hitFrame = UIEdgeInsetsInsetRect(bounds, hitTestEdgeInsets)
301+
return CGRectContainsPoint(hitFrame, point)
302+
}
291303
}

Keyboard/KeyboardLayoutEngine/KeyboardRow.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class KeyboardRow: UIView {
4949
public var characters: [AnyObject]!
5050
/// Managed by KeyboardLayout
5151
internal var isPortrait: Bool = true
52+
public var hitTestEdgeInsets: UIEdgeInsets = UIEdgeInsets(top: -6, left: -6, bottom: -6, right: -6)
5253

5354
// MARK: Init
5455
public init(style: KeyboardRowStyle, characters: [AnyObject]) {
@@ -164,6 +165,16 @@ public class KeyboardRow: UIView {
164165
return opt
165166
}
166167

168+
// MARK: Hit Test
169+
public override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
170+
if UIEdgeInsetsEqualToEdgeInsets(hitTestEdgeInsets, UIEdgeInsetsZero) {
171+
return super.pointInside(point, withEvent: event)
172+
}
173+
174+
let hitFrame = UIEdgeInsetsInsetRect(bounds, hitTestEdgeInsets)
175+
return CGRectContainsPoint(hitFrame, point)
176+
}
177+
167178
// MARK: Button Highlighting
168179
public func highlightButton(button: KeyboardButton) {
169180
for character in characters {

KeyboardLayoutEngine.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "KeyboardLayoutEngine"
19-
s.version = "0.8"
19+
s.version = "0.8.1"
2020
s.summary = "⌨️ Simplest custom keyboard generator for iOS ever!"
2121

2222
# This description is used to generate tags and improve search results.
@@ -336,7 +336,7 @@ optional func defaultKeyboardDidPressReturnButton(defaultKeyboard: DefaultKeyboa
336336
# Supports git, hg, bzr, svn and HTTP.
337337
#
338338

339-
s.source = { :git => "https://github.com/cemolcay/KeyboardLayoutEngine.git", :tag => "0.8" }
339+
s.source = { :git => "https://github.com/cemolcay/KeyboardLayoutEngine.git", :tag => "0.8.1" }
340340

341341

342342
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

0 commit comments

Comments
 (0)