0

我需要在弹出框上显示 UIActionSheet,并且此弹出框有一个指向 Cocos2D 上的元素的箭头。

我需要根据将显示 UIActionSheet 的导演视图坐标计算此元素的 boundingBox rect,因此操作表箭头将指向它。

我怎么做?

4

1 回答 1

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];
于 2012-06-15T02:02:36.643 回答