Skip to content

Commit e816b8f

Browse files
committed
Skip the accessory view to dismiss keyboard on iPad
1 parent d453ccd commit e816b8f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Example/Example.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@
457457
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
458458
PRODUCT_BUNDLE_IDENTIFIER = com.polydice.ICInputAccessoryExample;
459459
PRODUCT_NAME = "$(TARGET_NAME)";
460+
TARGETED_DEVICE_FAMILY = "1,2";
460461
};
461462
name = Debug;
462463
};
@@ -470,6 +471,7 @@
470471
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
471472
PRODUCT_BUNDLE_IDENTIFIER = com.polydice.ICInputAccessoryExample;
472473
PRODUCT_NAME = "$(TARGET_NAME)";
474+
TARGETED_DEVICE_FAMILY = "1,2";
473475
};
474476
name = Release;
475477
};

Source/ICKeyboardDismissTextField.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,31 @@ public class ICKeyboardDismissTextField: UITextField {
3838

3939
override public init(frame: CGRect) {
4040
super.init(frame: frame)
41-
inputAccessoryView = accessoryView
41+
setUpAccessoryView()
4242
}
4343

4444
required public init?(coder aDecoder: NSCoder) {
4545
super.init(coder: aDecoder)
46-
inputAccessoryView = accessoryView
46+
setUpAccessoryView()
4747
}
4848

4949
// MARK: - UIResponder
5050

5151
override public func becomeFirstResponder() -> Bool {
52-
accessoryView.alpha = 1
52+
if UI_USER_INTERFACE_IDIOM() == .Phone {
53+
accessoryView.alpha = 1
54+
}
5355
return super.becomeFirstResponder()
5456
}
5557

5658
// MARK: - Private Methods
5759

60+
private func setUpAccessoryView() {
61+
if UI_USER_INTERFACE_IDIOM() == .Phone {
62+
inputAccessoryView = accessoryView
63+
}
64+
}
65+
5866
@IBAction private func dismiss(sender: UIButton) {
5967
resignFirstResponder()
6068
UIView.animateWithDuration(0.3) {

0 commit comments

Comments
 (0)