我有自定义UIView
self.commentView = [[[NSBundle mainBundle] loadNibNamed:@"commentView" owner:self options:nil] firstObject];
self.commentView.userInteractionEnabled = YES;
CGRect frame = CGRectMake(0, [[UIScreen mainScreen]bounds].size.height, [[UIScreen mainScreen]bounds].size.width, 52);
[self.commentView setFrame:frame];
[self addSubview:self.commentView];
添加手势识别器
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapping)];
[self.commentView addGestureRecognizer:tap];
自定义视图包含UITextView
。我注册键盘通知并在键盘出现时更改我的自定义视图框
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardAppeared:)
name:UIKeyboardDidShowNotification
object:nil];
- (void)keyboardAppeared:(NSNotification*)notificationn{
NSDictionary* keyboardInfo = [notificationn userInfo];
NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue];
CGRect frame = self.commentView.frame;
frame.origin.y = (keyboardFrameBeginRect.origin.y - frame.size.height);
[UIView animateWithDuration:.1f animations:^{
[self.commentView setFrame:frame];
self.commentView.alpha = 1.0f;
}];
keyboard = keyboardFrameBeginRect.origin.y;
}
在我的'点击'方法中,我有一个NSLog
。当我最初添加commentView
并点按视图时,触摸工作并调用tapping
。显示键盘并且commentView
的框架在键盘上方移动后,不再调用“点击” - 触摸事件停止。
我还有关于键盘何时被解雇的通知。在此方法中,我将帧设置回原始帧。触摸再次开始起作用。
修改
这是我添加commentView
的方式。以上addSubview:
正在测试:
- (void) showCommentView{
CGRect frame = CGRectMake(0, [[UIScreen mainScreen]bounds].size.height-52, [[UIScreen mainScreen]bounds].size.width, 52);
[self.commentView setFrame:frame];
if (![self.subviews containsObject:self.commentView]) {
[self addSubview:self.commentView];
}
[self.commentView.commentTextView becomeFirstResponder];
CGRect framer = [self convertRect:self.commentView.postButton.frame fromView:self.commentView];
NSLog(@"SUPERVIEW: %f", framer.origin.y);
}
我注释了commentTextView becomeFirstResponder
行,点按即可。如果我离开此行,则会调用keyboardAppeared
,并且一旦更改了帧,则点按不再有效。所以我认为commentView
的框架实际上没有改变。
答案 0 :(得分:0)
设置color
的{{1}}。我认为当KEY出现时,你的commentView框架没有正确调整大小。