ios中一些非常实用又容易被忽略的函数

来源:互联网 发布:有没有京东秒杀软件 编辑:程序博客网 时间:2024/04/27 22:32

1、- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event

如果return NO的话,则不会触发本VIEW的touch事件;这个point是事件接收者坐标系的点击位置,即当前VIEW的父VIEW,例如:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)];

[self.view addSubView:view];

那么点击self的任何一个位置都会触发该函数,返回NO的话,整个view(父view和当前view)都不会触发touch事件


2、- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsetsNS_AVAILABLE_IOS(5_0);

参考http://blog.csdn.net/lixing333/article/details/7589281

stretchableImageWithLeftCapWidth:topCapHeight 函数

参考http://blog.csdn.net/workhardupc100/article/details/6753304


3、- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;   // recursively calls -pointInside:withEvent:. point is in the receiver's coordinate system

该函数返回点击、移动等事件的point作用于哪个view上,一般与

- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view函数配合使用

例:http://unmi.cc/uiview-event-passthrough

4、- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view,返回转换后的point,

例:UIViewController *controller = [[UIViewController alloc] init];

UIView *view1 = [[UIView alloc] init];

[controller.view addSubView:view1];

UIView *view2 = [[UIView alloc] init];

[controller.view addSubView:view2];

view2在view1上面,如果点击view2上一个点为CGPoint point2,如果要把点击事件传递给view1的话,那么需要调用

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event函数return view1;想要知道point2对应在view1上的位置,

则:CGPoint point1 = [view2 convertPoint:point2 toView:view1];

5、

- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;

- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;

- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view

参考第4函数- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view

原创粉丝点击