ConvertPoint:fromView:在模拟器上运行良好,而不是在设备上
我很高兴看到这个:有关如何转换的答案子视图的点 它在模拟器上对我来说非常有效。
但由于某种原因,它在设备上不起作用...... 难道设备对视图位置进行了不同的管理——或者这只是另一个谜团?或者(希望)我写错了,你们可以帮忙...... :)
这是我的台词:
CGPoint yoel = [imagePressed.imageView convertPoint:imagePressed.frame.origin toView:nil];
I was happy to see this: answer for how to convert point of a subview
and it worked perfect for me on the simulator.
But for some reason it doesn't work on the device...
Can it be that the views positions are differently managed by the device - or is it just another mystery? Or (hopefully) I wrote it wrongly and you guys can help...
:)
here's my line:
CGPoint yoel = [imagePressed.imageView convertPoint:imagePressed.frame.origin toView:nil];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有一个与这个问题相关的不同问题,并且注意到在转换矩形时我必须考虑屏幕的比例。 (即它在模拟器上工作不是因为它是模拟器,而是因为模拟器处于非视网膜模式)
I had a different problem that relates to this question, and have noticed that I had to consider the scale of the screen when converting the rect. (i.e. it worked on the simulator not because it's the simulator, but because the simulator was in non-retina mode)
好的。这是 %d 和 %f 之间差异的一个教训:)
显然它工作完美。
我的错误是 - 我在模拟器上
DLog(@"yoel 是 %f", yoel.x);
DLog(@"yoel 是 %f", yoel.y);
就在设备上运行它之前,我将其更改为
DLog(@"yoel 是 %d", yoel.x);
DLog(@"yoel 是 %d", yoel.y);
由于 CGPoint 是浮动的,所以我得到了 0 而不是正确的坐标...
另一个教训 - 在将测试从模拟器切换到设备之前我永远不会更改代码,所以不要责怪苹果,而是责怪我自己:)
OK. that was a lesson in the difference between %d and %f :)
apparently it works perfect.
My mistake was - I had on the simulator
DLog(@"yoel is %f", yoel.x);
DLog(@"yoel is %f", yoel.y);
just before running it on the device I changed it to
DLog(@"yoel is %d", yoel.x);
DLog(@"yoel is %d", yoel.y);
since CGPoint is in float, I got 0 instead of the right coordinate...
Another lesson learnt - I shall never change code before I switch test from simulator to device, so not to blame apple but myself :)