我有几个案例,测试人员报告说,只要他们开始键入我的应用程序中的某些字段,键盘就会消失.我使用模拟器跟踪流程,并在手机上进行调试时,问题没有发生.然而,当我在一个不受束缚的手机上尝试时,它发生得相当一致.
这是一些相关的代码.所有这些都是在用户点击文本字段外时隐藏键盘.我的UIViews是我的Touchview类的子类,它接收所有触摸:
TouchView.h:
@protocol TouchViewDelegate <NSObject> -(UIView *) handletouches:(NSSet *)touches withEvent:(UIEvent *)event inView:(UIView *) view; @end @interface TouchView : UIScrollView @property (nonatomic,strong) id <TouchViewDelegate> touchDelegate; @end
TouchView.m:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView * touchedView = [super hitTest:point withEvent:event];
NSSet* touches = [event alltouches];
[self.touchDelegate handletouches:touches withEvent:event inView:touchedView];
return touchedView;
}
我将主视图配置为Touchview并将其包含在viewDidLoad中:
- (void)viewDidLoad
{
[super viewDidLoad];
HMWTouchView * touchView = (HMWTouchView*) self.view;
touchView.touchDelegate = self;
...
}
这是委托方法的实现:
-(UIView *) handletouches:(NSSet *)touches withEvent:(UIEvent *)event inView:(UIView *) hitView {
if (![hitView isKindOfClass:[UIButton class]]) {
[[UIResponder firstResponder] resignFirstResponder];
}
return self.view;
}
这看起来至少是IOS 8如何响应命中的变化.
解决方法
已在iOS 8.0.2中修复,不再需要.