0

This is so strange - for some reason, when my UIView animates up (once I tap my UITextView), my UITapGesture doesn't execute? E.g. 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];


}
Pranjal Bikash Das
  • 1,092
  • 9
  • 27
Brittany
  • 1,359
  • 4
  • 24
  • 63
  • I think you should take a look at this link https://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present – trungduc Nov 02 '17 at 03:23
  • Mine is a UITextView, not a UITextField... Works differently @trungduc – Brittany Nov 02 '17 at 03:24
  • sorry, my bad. But i think they are UiView, and you are using UIView animation. Maybe it will work. – trungduc Nov 02 '17 at 03:31
  • When you tap again, then `-(void)dismissKeyboard` is not being called or not? or just it is not animating but this method is being called? – 3stud1ant3 Nov 02 '17 at 03:37
  • @3stud1ant3 -(void)dismissKeyboard isn't being called. It's almost as if everything outside the UITextView is frozen once it's active. – Brittany Nov 02 '17 at 03:38
  • Just a suggestion: From the documentation of `beginAnimations:context:` I learnt this: "Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods to specify your animations instead." – 3stud1ant3 Nov 02 '17 at 03:41
  • It's a really bad idea to change the frame of a view controller's view. Why not just move the text view? – rmaddy Nov 02 '17 at 05:14
  • When the Tap gesture is not working -Check your View UI hierarchy- . check if something is on top or it is misplaced. – Bhumit Muchhadia Nov 02 '17 at 05:18
  • @BhumitMuchhadia It doesn't look like anything is on top of it? Also, View is always at he top of the hierarchy? E.g. View > tableview > tableviewcell... ? – Brittany Nov 03 '17 at 02:48

1 Answers1

0

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];
 }
Pranjal Bikash Das
  • 1,092
  • 9
  • 27
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • Animates up but again, view isn't able to be dismissed on tap. Seems everything except the textfield is frozen. – Brittany Nov 03 '17 at 02:13