Iphone 如何使用Cocos2d显示UIViewController和UIView?
我正在尝试使用Cocos2d构建一个iPhone应用程序,但我使用了四种类型的类 像吼叫-Iphone 如何使用Cocos2d显示UIViewController和UIView?,iphone,objective-c,cocos2d-iphone,Iphone,Objective C,Cocos2d Iphone,我正在尝试使用Cocos2d构建一个iPhone应用程序,但我使用了四种类型的类 像吼叫- @interface MenuScene : Scene {} @end @interface FlipView : UIImageView { CGPoint startTouchPosition; NSString *dirString; UIImageView *firstPieceView; UIImageView *secondPieceView; }
@interface MenuScene : Scene {}
@end
@interface FlipView : UIImageView
{
CGPoint startTouchPosition;
NSString *dirString;
UIImageView *firstPieceView;
UIImageView *secondPieceView;
}
@end
@interface HelloController : UIViewController
@end
@interface MenuLayer: Layer{
Todo *todo;
Menu * menu;
sqlite3 *database;
NSMutableArray *todos;
NSString *dirString;
CGPoint startTouchPosition;
}
@property (nonatomic, retain) NSMutableArray *todos;
-(void) button1: (id)sender;
-(void) button2: (id)sender;
-(void) black_jack: (id)sender;
@end
但是如何通过MenuLayer类显示FlipView和HelloController类。仅从代码中回答这个问题非常困难,但我认为您需要返回并阅读一些关于UIKit设计和CoCoCos2D编程的内容 HelloController是一个视图控制器-您不能“显示”它。视图控制器是一个类,用于答复来自视图的消息并控制其从模型中显示的数据 FlipView是一个ImageView,它是UIView的一个子类。要让UIKit呈现此图像,您需要使用
[UIView addSubView:…]将其添加到另一个视图中。
以下是我认为你想要做的:
正如我所说的,这是一个非常普遍的问题,我真的认为您应该回到文档并考虑您的设计。Apple文档很好,现在市场上有一些不错的iPhone书籍。如果你问如何将UIKit视图等附加到cocos2d iPhone项目,你只需要像这样做:
[[[Director sharedDirector] window] addSubview:myView];
更新至cocos 0.7,现在是:
[[[Director sharedDirector] openGLView] addSubview:myView];
在Cocos 0.99中:
[[[CCDirector sharedDirector] openGLView] addSubview:myView];
在cocos2.0中
[[[CCDirector sharedDirector] view] addSubview:myView];
我应该如何删除myView。当我在当前场景中按下一个按钮时,我移动到下一个场景。但是,添加的myView仍然出现在该场景中。谢谢。对不起,我问之前没有检查清楚。我得到了它。我在按钮的选择器中添加了以下代码。对于(子视图中的id sv){[((UIView*)sv)removeFromSuperview];[sv release];}还有一个问题。是否可以从nib唤醒UIView?目前版本2
[[[CCDirector sharedDirector]视图]addSubview:myView]代码>