iOS -获取点击的点在屏幕上的坐标,获取某个view在屏幕上的
2017-07-20 本文已影响0人
寻常_0
1.获取点击事件的点相对于屏幕的位置
如果点击事件是如下这个方法(将UIEvent当做参数传回来)
-(void)expandButtonClicked:(id)sender withEvent:(UIEvent*)event
那么点击的位置相对于屏幕的坐标就是:
UITouch* touch = [[event touchesForView:btn] anyObject];
CGPoint rootViewLocation = [touch locationInView:[FtAppDelegate shareAppDelegate].rootViewCtrl.view];
2.如果想知道一个view相对于屏幕或者另外一个view 的坐标,那么可以通过如下的方法得到:
UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
CGRect rect=[bView convertRect: bView.bounds toView:window];