I've found some questions similar to mine, but I still didn't get it.
I have the first class loaded that inherits CCScene, than I create an object go UIView class and use addChild and than I create an object of another UIView class and use addSubView. So CCScene -> UIView -> UIView
declaration of the first object:
startLayer.h:
@interface startLayer : CCScene {
@public
PlayScene *tView;
}
startLayer.m:
tView = [[PlayScene alloc]initWithFrame:CGRectMake(0, 0, 320, 520)];
tView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backGround.jpg"]];
CCUIViewWrapper* wrapper = [CCUIViewWrapper wrapperForUIView:tView];
[self addChild:wrapper];
the second object:
PlayScene.h:
@interface PlayScene : UIView {
@public
gameOverMenu* gorm ;
}
PlayScene.m:
gorm = [[gameOverMenu alloc]initWithFrame:CGRectMake(0, 0, 320, 520)];
gorm.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backGround.jpg"]];
[self addSubview:gorm];
So in gameOverMenu class I got UITextField subView:
UITextField* tf = [[UITextField alloc]initWithFrame:CGRectMake(100, 350, 150, 20)];
[tf setPlaceholder:@"Type your name.."];
[self addSubview:tf];
and I wanted to make keyboard move the View, I was told to write something like this in my RootViewController:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
}
-(void)keyboardDidShow:(NSNotification*)notification {
NSDictionary* userInfo = [notification userInfo];
NSValue* value = [userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [value CGRectValue].size;
// NSLog (@"%@", NSStringFromCGRect(gm.frame));
NSLog(@"%@", gm.superview);
// NSLog(@"%d", [gm.subviews count]);
gm.frame = CGRectMake(gm.frame.origin.x, gm.frame.origin.y, gm.frame.size.width, gm.frame.size.height-keyboardSize.height);
// NSLog (@"%@", NSStringFromCGRect(gm.frame));// NSLog(@"%@", gm.superview);
// NSLog(@"%d", [gm.subviews count]);
}
-(void)keyboarDidHide:(NSNotification*)notification {
NSDictionary* userInfo = [notification userInfo];
NSValue* value = [userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [value CGRectValue].size;
gm.frame = CGRectMake(gm.frame.origin.x, gm.frame.origin.y, gm.frame.size.width, gm.frame.size.height+keyboardSize.height);
}
@class gameOverMenu;
@interface RootViewController : UIViewController {
@public
gameOverMenu* gm;
}
but NSLog shows that gm object has no frame, no superclass and no subViews, I guess that means that I should use my form object here but I don't know how to get it from another class. I created cocos2d project by the way, so I had to write [self viewDidLoad]; in AppDelegate and I have no other methods implemented in RootViewController.