1

我很高兴看到这一点:回答如何转换子视图的点 ,它在模拟器上非常适合我。

但是由于某种原因,它在设备上不起作用......可能是视图位置由设备以不同方式管理 - 还是只是另一个谜?或者(希望)我写错了,你们可以帮忙...... :)

这是我的台词:

CGPoint yoel = [imagePressed.imageView convertPoint:imagePressed.frame.origin toView:nil];
4

2 回答 2

8

我有一个与这个问题相关的不同问题,并且注意到在转换矩形时我必须考虑屏幕的比例。(即它在模拟器上工作不是因为它是模拟器,而是因为模拟器处于非视网膜模式)

// the following convertRect is like asking a view: "what would one of your subviews (aView) have for a frame in my (toView) coordinate space if it were to become my subview?
    _originalFrame = [[aView superview] convertRect: aView.frame toView: self];

    CGFloat scale = [[UIScreen mainScreen] scale];

    _originalFrame.origin.x /= scale;
    _originalFrame.origin.y /= scale;
    _originalFrame.size.width /= scale;
    _originalFrame.size.height /= scale;

    NSLog(@"Converted Frame: %@", NSStringFromCGRect(_originalFrame));
于 2012-06-13T09:34:08.500 回答
2

好的。这是 %d 和 %f 之间区别的一个教训 :) 显然它工作得很好。

我的错误是-我在模拟器 DLog(@"yoel is %f", yoel.x); DLog(@"yoel is %f", yoel.y); 上运行它之前在设备上运行它, DLog(@"yoel is %d", yoel.x); DLog(@"yoel is %d", yoel.y); 因为CGPoint处于浮动状态,所以我得到了0而不是正确的坐标......

另一个教训 - 在我将测试从模拟器切换到设备之前,我永远不会更改代码,所以不要责怪苹果而是我自己 :)

于 2011-05-16T06:30:35.460 回答