问题描述
我很高兴看到这个:回答如何转换子视图的点它在模拟器上非常适合我.
I was happy to see this: answer for how to convert point of a subviewand 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...:)
这是我的线路:
CGPoint yoel = [imagePressed.imageView convertPoint:imagePressed.frame.origin toView:nil];
推荐答案
好的.这是 %d 和 %f 之间差异的教训:)显然它完美无缺.
OK. that was a lesson in the difference between %d and %f :)apparently it works perfect.
我的错误是 - 我在模拟器上有DLog(@"yoel 是 %f", yoel.x);DLog(@"yoel 是 %f", yoel.y);
就在设备上运行它之前,我将其更改为DLog(@"yoel is %d", yoel.x);DLog(@"yoel 是 %d", yoel.y);
由于 CGPoint 处于浮动状态,我得到了 0 而不是正确的坐标...
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 :)
这篇关于convertPoint:fromView: 在模拟器上运行良好,而不是在设备上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!