[英]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.