簡體   English   中英

Obj-C-在對UIView進行動畫處理后,UITapGestureRecognizer無法正常工作嗎?

[英]Obj-C - UITapGestureRecognizer doesn't work after UIView is animated?

這太奇怪了-由於某種原因,當我的UIView動畫化時(一旦我點擊UITextView ),我的UITapGesture不執行嗎? 例如,一旦將視圖設置為動畫並且UITextView處於活動狀態,則在視圖上的任何位置點擊都不會關閉該動畫視圖嗎? 但是,如果我在動畫UITapGesture之前在視圖上點擊任意位置, 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];


}

一旦嘗試,

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM