iOS Sharecontext Tapping on Suggestion Intent Property of Extensioncontext Is Nil

How to handle background tap in UICollectionView

This is how I tried to set gesture recognizer to background view. I managed to get separate events.

self.collectionView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg"]];
self.collectionView.backgroundView.userInteractionEnabled = YES;

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap:)];
self.collectionView.backgroundView.gestureRecognizers = @[tapRecognizer];

iOS - Dismiss keyboard when touching outside of UITextField

You'll need to add an UITapGestureRecogniser and assign it to the view, and then call resign first responder on the UITextField on it's selector.

The code:

In viewDidLoad

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];

[self.view addGestureRecognizer:tap];

In dismissKeyboard:

-(void)dismissKeyboard 
{
[aTextField resignFirstResponder];
}

(Where aTextField is the textfield that is responsible for the keyboard)

Swift 3 version looks like that

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.dismissKeyboard (_:)))
self.view.addGestureRecognizer(tapGesture)

For dismissKeyboard

@objc func dismissKeyboard (_ sender: UITapGestureRecognizer) {
aTextField.resignFirstResponder()
}


Related Topics



Leave a reply



Submit