【问题标题】:NSPoint and IMKCandidate Window PlacementNSPoint 和 IMKCandidate 窗口放置
【发布时间】:2012-05-25 21:11:45
【问题描述】:

我正在使用 inputmethodkit 并尝试在某些文本下方放置一个窗口。

_currentClient 是一个IMKTextInput 实例

candidates 是 IMKCandidates 实例

// Get the current location to place the window
NSRect tempRect = NSMakeRect(0, 0, 0, 0);
NSDictionary* clientData = [_currentClient attributesForCharacterIndex:0 lineHeightRectangle:&tempRect];
NSPoint* windowInsertionPoint = (NSPoint*)[clientData objectForKey:@"IMKBaseline"];
...
[candidates setCandidateFrameTopLeft:*windowInsertionPoint];
[candidates showCandidates];

现在,我知道windowInsertionPoint 变量很好,当我调试时我可以看到它的值,例如:NSPoint: {647,365}

但是,当我使用它时,候选窗口只显示在屏幕的左下角。我以前没有处理过屏幕放置问题,因此非常感谢您的帮助。

如果我将任意静态值传递给setCandidateFrameTopLeft,它将被放置在屏幕中。以下作品:

[candidates setCandidateFrameTopLeft:NSMakePoint(401, 354)];

是指针问题吗?

【问题讨论】:

    标签: objective-c pointers input-method-kit


    【解决方案1】:

    好的,解决方法是我是个白痴。这是您需要的代码:

    NSRect tempRect;
    NSDictionary* clientData = [_currentClient attributesForCharacterIndex:0 lineHeightRectangle:&tempRect];
    NSPoint windowInsertionPoint = NSMakePoint(NSMinX(tempRect), NSMinY(tempRect));
    

    IMKTextInput attributesForCharacterIndex 的文档说

    lineRect:返回时,一个矩形框出一个 1 像素宽的矩形,该矩形具有线的高度。这个矩形的方向与直线的方向相同。

    这意味着它将一个 NSRect 返回到您为 lineHeightRectangle 值传递给它的变量中。重要的一点是,该 NSRect 的位置就是您要搜索的字符的位置。因此,您只需从该矩形中创建一个点并使用 NSMinY 作为 Y 值。矩形只有一个像素宽,所以 X 的 Min/Max 基本相同。

    【讨论】:

      【解决方案2】:

      您可能不再有这个问题,但这也适用于未来:

                  [candidates show:kIMKLocateCandidatesBelowHint];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-09-11
        • 2023-03-21
        • 2010-09-07
        • 2011-04-30
        • 1970-01-01
        • 2011-04-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多