代码改变世界

GMGridView cell button

2012-11-16 21:26  -king  阅读(333)  评论(0编辑  收藏  举报

在GMGridView的cell里面添加button的时候,不能响应touch up inside事件。

解决方法:https://github.com/gmoledina/GMGridView/issues/68

在gmgridview.m文件中作修改,添加以下方法可解决问题。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ( gestureRecognizer == _tapGesture || gestureRecognizer == _sortingLongPressGesture ) {
        if ( [touch.view isDescendantOfView:self] ) {
            // Test if the touched view is a subview of a control
            for ( UIView *view = touch.view ; view != self ; view = view.superview )
                if ( [view isKindOfClass:[UIControl class]] )
                    return NO;
        }
    }

    return YES;
}