2017-11-02 6 views
0

これは私のUIViewが (私がUITextViewをタップした後)にアニメーションするとき何らかの理由で私のUITapGestureは実行されません。例えば。ビューがアニメーション化され、UITextViewがアクティブな状態でビューの任意の場所をタップすると、アニメーション化されたビューは閉じられません。しかし、アニメーション化する前にビューのどこかをタップすると、UITapGestureはうまく実行されます - これはなぜですか?UIViewがアニメーション化された後にObj-C - UITapGestureRecognizerが機能しない?

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


} 
+0

私はあなたがこのリンクを見てみるべきだと思いますhttps://stackoverflow.com/questions/1126726/how- to-make-a-uitextfield-move-up-when-keyboard-is-present – trungduc

+0

私はUITextFieldではなく、UITextViewです...動作が違う@trungduc – Brittany

+0

申し訳ありません。しかし、私は彼らがUiViewであり、UIViewアニメーションを使用していると思います。多分それはうまくいくでしょう。 – trungduc

答えて

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]; 
} 
+0

もう一度アニメーションしますが、タップで表示を閉じることはできません。テキストフィールドを除くすべてがフリーズしているようです。 – Brittany

関連する問題