如何获取点击屏幕的位置 屏幕UITouch点击点击屏幕的坐标 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 创建一个UIView的子类,比如叫reportView,然后在这个类里实现touchesbegin方法之后在你的VC的self.view的第一层就加载和self.view一样frame的reportView,这样reportView里获取的坐标就都是全屏的了顺便给个touchbegin中获取坐标的语句CGPoint touchPos = [touch locationInView:self.view]; 忘记说一句,你要把vc里其他的控件都加在reportView上,当然你也可以直接让vc的view从reportView继承 不知道你view的视图层级是怎样的。不过touchbegin方法应该会设置,方便的话上代码吧 找到最底层的view在获取坐标。 使用touchesBegan 方法挺好的,如果你是想获取相对手机屏幕的坐标,就使用相对appdelegate.window的坐标,这个是所有view最底层的父视图-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{// UIWindow * window1 = (UIWindow *)self.view.superview;// NSLog(@"%@",window1); AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate; UIWindow * window2 = app.window; NSLog(@"%@",window2); UITouch * touch = touches.anyObject; CGPoint location2 = [touch locationInView:window2]; NSLog(@"%@",NSStringFromCGPoint(location2));}就是状态栏点击没有效果。 可以按1楼给的方法去做。在-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event里获取当前点击点的位置的方法UITouch * touch = touches.anyObject;CGPoint location2 = [touch locationInView:self]; 是这样的 我的vc下 是个滑块选项卡,类似网易新闻那种。滑块选项卡下有两个view,我只需要在其中一个view实现这个方法。还有一点 不是很明白, 如你所说,我创建了一个你说的reportview,并且在上面放上了我的各种控件,但是这个reportview还是没有办法实现我点击控件上,就调用了reportview上得touchesbegin的方法。- -大神 有办法么 是这样的 我的vc下 是个滑块选项卡,类似网易新闻那种。滑块选项卡下有两个view,我只需要在其中一个view实现这个方法。还有一点 不是很明白, 如你所说,我创建了一个你说的reportview,并且在上面放上了我的各种控件,但是这个reportview还是没有办法实现我点击控件上,就调用了reportview上得touchesbegin的方法。- -大神 有办法么这个呢 如何找- -能详细点么你的试图都是加载在self.view上吧,一层一层的找,我以前遇到过这种问题,不知道一样不一样,我再做项目的时候,在tableview中用到过,你看看的试图的层次结构,有一个方法,一层层找最底层view的,在view controal里面用的。你找找 memory 内存问题 uitableviewcell Objective-C和Objective-C++的区别只是对C和C++的兼容性吗? 新手提问,关于Exception的问题 关于CALayer的使用 想学IPHONE上面的程序开发吗? 怎么通过浏览器打开app iOS view显示不出控件 入门注意什么? 求解OC如何做到使用拼接字符串创建一系列特定地址的文件 求助,iOS版CAB压缩或者C版 请问如何编码控制Label中文字的位置 疯了,到底要怎样才能横屏!
之后在你的VC的self.view的第一层就加载和self.view一样frame的reportView,这样reportView里获取的坐标就都是全屏的了顺便给个touchbegin中获取坐标的语句
CGPoint touchPos = [touch locationInView:self.view];
// UIWindow * window1 = (UIWindow *)self.view.superview;
// NSLog(@"%@",window1);
AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate;
UIWindow * window2 = app.window;
NSLog(@"%@",window2);
UITouch * touch = touches.anyObject;
CGPoint location2 = [touch locationInView:window2];
NSLog(@"%@",NSStringFromCGPoint(location2));
}
就是状态栏点击没有效果。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
里获取当前点击点的位置的方法
UITouch * touch = touches.anyObject;
CGPoint location2 = [touch locationInView:self];
还有一点 不是很明白, 如你所说,我创建了一个你说的reportview,并且在上面放上了我的各种控件,但是这个reportview还是没有办法实现我点击控件上,就调用了reportview上得touchesbegin的方法。
- -大神 有办法么
还有一点 不是很明白, 如你所说,我创建了一个你说的reportview,并且在上面放上了我的各种控件,但是这个reportview还是没有办法实现我点击控件上,就调用了reportview上得touchesbegin的方法。
- -大神 有办法么这个呢