2012-05-18 64 views
1

我正在使用inputmethodkit并试图在某些文本下放置一个窗口。NSPoint和IMKCandidate窗口布局

_currentClient是IMKTextInput实例

候选人是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)]; 

这是指针问题吗?

回答

0

好的,解决这个问题的办法是我是个白痴。下面是代码,您需要:

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

IMKTextInput attributesForCharacterIndex文档说

lineRect:在返回时,该框架与该行的高度的一个像素宽的矩形的矩形。这个矩形的方向与线的方向相同。

这意味着它返回一个NSRect到你通过它的lineHeightRectangle值的变量中。重要的一点是,该NSRect的位置是您正在搜索的角色的位置。所以,你需要从那个矩形中取一个点,并使用NSMinY作为Y值。矩形只有一个像素宽,所以X的最小/最大值基本相同。

0

你可能没有这个问题了,但这个工程也为未来:

  [candidates show:kIMKLocateCandidatesBelowHint];