This is so strange - for some reason, when my UIView
animates up (once I tap my UITextView
), my UITapGesture
doesn't execute? Eg tapping anywhere on the view once the view is animated and UITextView
is active doesn't dismiss the animated view? However if I tap anywhere on the view BEFORE it animates, UITapGesture
executes just fine - why is this?
ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.replyField.delegate = self;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
}
-(void)dismissKeyboard {
[self animateTextView:NO];
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[self animateTextView: YES];
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
[self animateTextView:NO];
}
- (void) animateTextView:(BOOL) up
{
const int movementDistance = 206; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
int movement= movement = (up ? -movementDistance : movementDistance);
NSLog(@"%d",movement);
[UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.inputView.frame, 0, movement);
[UIView commitAnimations];
}
Once try like,
- (void) animateTextView:(BOOL) up
{
UIViewAnimationOptions options = UIViewAnimationOptionAllowUserInteraction;
const int movementDistance = 206; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
int movement= movement = (up ? -movementDistance : movementDistance);
[UIView animateWithDuration:movementDuration
delay:0.0
options:options
animations:^{
self.view.frame = CGRectOffset(self.inputView.frame, 0, movement);
}
completion:nil];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.