John-Lluch / SWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !
Other
4.52k stars 989 forks source link

dismiss keyboard #558

Open maozelit opened 8 years ago

maozelit commented 8 years ago

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?

iDevelopper commented 8 years ago

[textField resignFirstResponder];

maozelit commented 8 years ago

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..

iDevelopper commented 8 years ago

Use the delegate method

// Optional Check the position, and if position == FrontViewPositionRight // textView.resignFirstResponder()

iDevelopper commented 8 years ago
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()
    }
maozelit commented 8 years ago

Thank you very much!!:) it works!

iDevelopper commented 8 years ago

You're welcome! ++

kanumuri9593 commented 8 years ago

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

david-littlefield commented 6 years ago

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.

iDevelopper commented 6 years ago

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:

SWTextFieldSample.zip

david-littlefield commented 6 years ago

@iDevelopper Thank you for your quick response! And for the sample! It works great!