gpt4 book ai didi

iphone - iOS: [X convertPoint: somePoint toView: nil];无法返回窗口坐标

转载 作者:行者123 更新时间:2023-11-28 17:47:53 25 4
gpt4 key购买 nike

我正在编写一个方法,它应该接收一个点:'in_centre',它将在当前 View 的坐标系中(也作为另一个参数传递:'target')

我需要将这个点转换成窗口坐标。

文档说我应该通过将这里的第二个参数设置为 nil 来做到这一点:

centerPoint = [target convertPoint:in_centre toView:nil];  // get in Window Coords
NSLog(@"passed in (vc): %@", NSStringFromCGPoint(in_centre));
NSLog(@"centerPoint_wc: %@", NSStringFromCGPoint(centerPoint));

但是输出显示它什么也没做。

2010-11-24 07:32:45.815 ChordWheel[3195:207] 传入 (vc):{150, 150}
2010-11-24 07:32:45.816 ChordWheel[3195:207] centerPoint_wc: {150, 150}

这是错误的——它应该是 iPhone 屏幕的中心:{160, 240}

这是怎么回事?

编辑:感谢您的这些建议——我试过了,但仍然不高兴:

- (id) initWithFrame: (CGRect) theFrame
target: (id) p_target
actionPlayChord: (SEL) p_actionPlayChord
actionSettings: (SEL) p_actionSettingsClick
{
target = p_target;
actionPlayChord = p_actionPlayChord;

self = [super initWithFrame: theFrame];

if ( ! self )
return nil;

CGPoint centre = CGPointMake(theFrame.size.width / 2.0,
theFrame.size.height / 2.0);

CGPoint c_wc = [self convertPoint: centre toView: nil];
CGPoint c_wc2 = [self convertPoint: centre toView: self.window];

NSLog(NSStringFromCGRect(theFrame));
NSLog(NSStringFromCGPoint(centre));
NSLog(NSStringFromCGPoint(c_wc));
NSLog(NSStringFromCGPoint(c_wc2));

2010-11-24 14:33:55.202 ChordWheel[3452:207] {{10, 90}, {300, 300}}
2010-11-24 14:33:55.202 弦轮 [3452:207] {150, 150}
2010-11-24 14:33:55.203 弦轮 [3452:207] {150, 150}
2010-11-24 14:33:55.204 弦轮 [3452:207] {150, 150}

最佳答案

我上次检查时它对我有用,但它可能在操作系统版本之间发生了变化。您可以使用 [v convertPoint:p toView:v.window](一个窗口是一个 View ),但是对于不是全屏窗口的窗口(“窗口基坐标”),这可能会返回一些不同的东西"可能相对于窗口所在的屏幕,例如,而不是相对于窗口的左上角)。

关于iphone - iOS: [X convertPoint: somePoint toView: nil];无法返回窗口坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4262501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com