SWRevealViewController
SWRevealViewController copied to clipboard
dismiss keyboard
Hello, I need a little help.. I have a textfield in a scene and if i tap the menu button when the keyboard is open the menu appears but the keyboard covers it. what can i do to solve it?
[textField resignFirstResponder];
I tried func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool { textView.resignFirstResponder() return false } it didn't work.. i'm a little new so if you can explain more..
Use the delegate method
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position;
// Optional Check the position, and if position == FrontViewPositionRight // textView.resignFirstResponder()
import UIKit
class TextFieldViewController: UIViewController,SWRevealViewControllerDelegate {
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var menuButton:UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
if revealViewController() != nil {
menuButton.target = revealViewController()
menuButton.action = "revealToggle:"
self.navigationController!.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
revealViewController().delegate = self
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition) {
textField.resignFirstResponder()
}
Thank you very much!!:) it works!
You're welcome! ++
Hi How I can call the above method I need to change the Menu Button Icon when it is touched or menuView is opened
thank you
The Context: I used the example posted by @iDevelopper, Mar 9, 2016, to create a custom solution for conflicting gesture recognizers. Within the same view controller, I had one tap gesture recognizer to toggle the reveal view controller, and another to dismiss the keyboard.
The problem: The revealToggle tap gesture recognizer stopped working after I added a second dismissKeyboard tap gesture recognizer. It appeared the second had cancelled out the first, or replaced it.
You can't add the same gesture recognizer twice to a view. Then if you want a tap gesture recognizer for the keyboard, create a new one. This is a sample:
@iDevelopper Thank you for your quick response! And for the sample! It works great!