ITeye博客

2014.12.15 ——— ios开发之hitTest pointInside

lipeng88213 · 2014-12-15 17:43 · 移动开发 · Markdown

2014.12.15 ——— ios开发之hitTest pointInside 参考:http://blog.csdn.net/bravegogo/article/details/19936689

两个方法的意思 可以参考上面这边文章

我用到的场景主要是:

UITableView 每一个cell 右划出现删除,点击其他地方取消删除按钮

思路:

捕获右划,建立一个UITableView的子view,大小与其一样,并且这个子view 重写hitTest方法,来判断是否点击了删除按钮

代码:

#import <UIKit/UIKit.h>

@interface MyView : UIView
{
}

@property(nonatomic, assign) UIView *ignoreView;

- (id)initWithParentView:(UIView *)parent ignoreView:(UIView *)ignoreView;

#import "MyView.h"
@implementaion MyView

- (id)initWithParentView:(UIView *)parent ignoreView:(UIView *)ignoreView{
   self = [[myview alloc] init];
   if(self){
        self.frame = parent.frame;
        self.backgroundColor = [uicolor clearcolor];
        [parent addsubview:self];
        _ignoreView = ignoreView;
        self.userInteractionEnabled = YES;
   }
   return self;
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
   UIView *result = [super hittest:point withevent:event];
   CGPoint buttonPoint = [_ignoreview convertpoint:point fromview:self];
   if([_ignoreview pointinside:buttonpoint withevent:event]){
       return _ignoreView;
   }
   return result;
}

这样之后 当点击到删除按钮了,虽然删除按钮其实没有捕获到 但是通过hitTest指向了删除按钮,就可以再删除按钮的代理方法来处理逻辑了

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。