IOS 获取点击的点在屏幕上的坐标,获取某个view在屏幕上的位置

  1. 获取点击事件的点相对于屏幕的位置spa

     若是点击事件是以下这个方法(将UIEvent当作参数传回来)事件

-(void)expandButtonClicked:(id)sender withEvent:(UIEvent*)eventit

那么点击的位置相对于屏幕的坐标就是:io

UITouch* touch = [[event touchesForView:btn] anyObject];event

CGPoint rootViewLocation = [touch locationInView:[FtAppDelegate shareAppDelegate].rootViewCtrl.view];方法


2.若是想知道一个view相对于屏幕或者另一个view 的坐标,那么能够经过以下的方法获得:touch

UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
    CGRect rect=[bView convertRect: bView.bounds toView:window];view

相关文章
相关标签/搜索