0

I am trying to add facebook to my ios xcode game. I can add a facebook login button on a single view application like this:

FBLoginView *loginview = [[FBLoginView alloc] init];

loginview.frame = CGRectOffset(loginview.frame, 5, 5);
loginview.delegate = self;

[self.view addSubview:loginview];

[loginview sizeToFit];

But when i try and add this to my cocos2d project I get an error on this line:

[self.view addSubview:loginview];

I have tried adding it as a child but that doesn't work either. How can I add the button to the screen?

4

2 回答 2

4

[[[CCDirector sharedDirector] openGLView] addSubview:myview];

它的工作正常,但 openGLView 已被弃用

您可以使用:

[[[CCDirector sharedDirector] view] myView];

于 2013-07-10T09:13:59.260 回答
3

由于Cocos2D场景不是subclassedfrom UIViews,所以不能直接将 a 添加UIViewsubview

试试这篇文章中的解决方案:How to create a new UIView programmatically in cocos2d?

关键部分是(iOS<7):

[[[CCDirector sharedDirector] openGLView] addSubview:myview];

对于 iOS 7,请使用:

[[[CCDirector sharedDirector] view]addSubview:myview];
于 2013-07-02T20:33:48.060 回答