Reputation:
For example, in chat apps when a user is composing a message, app shows typing
icon, but if the user stopped composing in the middle of the message, app disappears composing
icon.
How the app can detects that user stopped typing in the middle of composing or still typing?
For example:
hel (show typing icon)
stopped typing (hide typing icon)
lo (continue typing - show again)
Upvotes: 1
Views: 2206
Reputation: 1658
First, you need to detect when user start typing. You can addTarget
your UITextField
object. When user stop typing, just set a timer in that target like that;
textField.addTarget(self, action: "textFieldDidChange:", forControlEvents: UIControlEvents.EditingChanged)
func textFieldDidChange(textField: UITextField) {
textTimer?.invalidate()
textTimer = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: Selector("textFieldStopChanging:"), userInfo: nil, repeats: false)
print("Start typing")
}
func textFieldStopEditing(sender: NSTimer) {
print("Stop typing")
}
Upvotes: 3
Reputation: 420
If you are using UITextField below method may help you.
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
}
If you are using UITextView try below
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
}
Upvotes: 0