これは私の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];
}
私はあなたがこのリンクを見てみるべきだと思いますhttps://stackoverflow.com/questions/1126726/how- to-make-a-uitextfield-move-up-when-keyboard-is-present – trungduc
私はUITextFieldではなく、UITextViewです...動作が違う@trungduc – Brittany
申し訳ありません。しかし、私は彼らがUiViewであり、UIViewアニメーションを使用していると思います。多分それはうまくいくでしょう。 – trungduc