在插件开发过程中发现flutter页面通过present跳转原生页面后,原生页面上的点击响应下面的Flutter页面中的点击事件。这个问题出现很早了,github中有人提了issue但是一直没有修复。
解决方案:
1.重写从FlutterViewController呈现的UIViewController的4个方法
这可以防止将未处理的事件传播到 FlutterViewController
Swift
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
}
Objective-C
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
}
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
}
-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
}
2. 停止从 FlutterViewController 做 Present
页面跳转时切换window的根控制器到原生控制器即可,在返回时再切换回flutter中。
评论区