SWRevealViewController icon indicating copy to clipboard operation
SWRevealViewController copied to clipboard

dismiss keyboard

Open maozelit opened this issue 8 years ago • 10 comments

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?

maozelit avatar Mar 09 '16 09:03 maozelit

[textField resignFirstResponder];

iDevelopper avatar Mar 09 '16 09:03 iDevelopper

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

maozelit avatar Mar 09 '16 09:03 maozelit

Use the delegate method

  • (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position;

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

iDevelopper avatar Mar 09 '16 09:03 iDevelopper

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()
    }

iDevelopper avatar Mar 09 '16 10:03 iDevelopper

Thank you very much!!:) it works!

maozelit avatar Mar 09 '16 10:03 maozelit

You're welcome! ++

iDevelopper avatar Mar 09 '16 10:03 iDevelopper

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

kanumuri9593 avatar Jun 14 '16 18:06 kanumuri9593

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.

david-littlefield avatar Dec 25 '17 00:12 david-littlefield

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

iDevelopper avatar Dec 25 '17 09:12 iDevelopper

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

david-littlefield avatar Dec 25 '17 17:12 david-littlefield