在UIView动画后,Obj-C - UITapGestureRecognizer不起作用?

时间:2017-11-02 03:10:25

标签: ios objective-c uitapgesturerecognizer

这很奇怪 - 出于某种原因,当我UIView动画时 (一旦我点按UITextView),我的UITapGesture就不会执行了?例如。在视图设置动画并且UITextView处于活动状态时,点按视图上的任意位置都不会忽略动画视图?但是,如果我在视图上的任何位置点按它之前动画,UITapGesture执行得很好 - 为什么会这样?

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];


}

1 个答案:

答案 0 :(得分:0)

一旦尝试,

- (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];
 }