Skip to content

Instantly share code, notes, and snippets.

@canaksoy
Created July 23, 2016 11:06
Show Gist options
  • Save canaksoy/2e2b810783507bec7a170c005707e7d2 to your computer and use it in GitHub Desktop.
Save canaksoy/2e2b810783507bec7a170c005707e7d2 to your computer and use it in GitHub Desktop.
shouldChangeTextInRange (user is typing logic)
@property int isTyping;
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
[self startTyping];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(stopTyping) object:nil];
[self performSelector:@selector(stopTyping) withObject:nil afterDelay:0.5];
return YES;
}
- (void)startTyping {
if (self.isTyping==0) {
self.isTyping=1;
[self sendTypingStartData];
}
}
- (void)stopTyping {
self.isTyping=0;
[self sendTypingStopData];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment