我正在使用inputmethodkit并尝试放置一些文本下面的窗口。

_currentclient是一个生成的icetagcode实例

候选是一个生成的iconicetagcode实例

// 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];
.

现在,我知道,当我调试我可以看到它的值时,IMKTextInput变量很好,例如:nspoint:{647,365} 但是,当我使用此时,候选窗口只会在屏幕的左下角显示。我之前没有使用屏幕放置东西,因此有助于帮助。

如果我将任意静态值传递给生成的静态值,它会放在屏幕中。以下作品:

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

是一个指针问题?

有帮助吗?

解决方案

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

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

imktextinput属性forcharacterindex

linerect:返回,矩形框架,框架的一个像素宽矩形,高度线。这种矩形与线导向的方式相同。

这意味着它将NSRECT返回到传递的变量中,以便将其传递给lineHeightRectangle值。重要点是NSRECT的位置是您正在搜索的角色的位置。所以,那么你需要从那个矩形开始点点,并为y值使用nsminy。矩形只是单个像素宽,所以min / max for x基本相同。

其他提示

你可能没有这个问题了,但这也是如此:

            [candidates show:kIMKLocateCandidatesBelowHint];
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top