2012-06-15 48 views

回答

2

這是一個快速的示例中,我創建的,就在UIPopoverController更改爲UIActionSheet。

CCNode* node = (CCNode *)sender; 
CGPoint worldPoint = [node convertToWorldSpace:CGPointZero]; 
CGRect rect = [sender boundingBox]; 
rect.origin = worldPoint; 
// Convert position based on Apple's anchor point from cocos2d's anchor point 
rect.origin.y = rect.origin.y + rect.size.height; 
CGPoint convertedLocation = [[CCDirector sharedDirector] convertToUI:ccp(rect.origin.x, rect.origin.y)]; 
rect.origin = convertedLocation; 

UIViewController* viewController= [[UIViewController alloc] init]; 
[[viewController view] setBackgroundColor:[UIColor greenColor]]; 
UIPopoverController* c = [[UIPopoverController alloc] initWithContentViewController:viewController]; 
[c presentPopoverFromRect:rect inView:[[CCDirector sharedDirector] view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
+0

都能跟得上。這不是給我正確的座標。 X似乎或多或少是對的,但Y是完全錯誤的。 – SpaceDog

+0

注意:這個精靈是在一個圖層內的另一個精靈......這是否有什麼區別? – SpaceDog

+1

是的,它很重要,邊界框返回不同的座標,在主圖層上的精靈上試試這個。看看它是否正確 –

相關問題