ksnowlv

回顾过去,总结以往;立足现在,铭记当下;技术为主,笔记而已.

iOS中不完全在父UIView frame中的UIView如何响应事件

| Comments

iOS开发中,如何使一个不完全在父UIView的frame中的UIView响应事件呢?

可以通过在父UIView中重写pointInside:withEvent即可.

1
2
3
4
5
6
7
8
9
10
11
12
13
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    for (UIView *subview in self.subviews) {

        CGPoint subviewPoint = [self convertPoint:point toView:subview];

        if ([subview pointInside:subviewPoint withEvent:event]) {

            return YES;
        }
    }

    return [super pointInside:point withEvent:event];
}

在腾讯地图sdk中关于标注覆盖物(QAnnotationView)弹出的气泡采用该方法。

  • 气泡是标注的子UIView,但是,并不完全在标注的frame中。
  • 如果使气泡可以响应事件,则在QAnnotationView中重写pointInside:withEvent

Comments

comments powered by Disqus
Included file 'custom/after_footer.html' not found in _includes directory