I am having a strange problem when I switch views using the UIView begin, set and commit animations.
For some reason when I change the views it is pushing the elements that I have on the screen up by about 10 pixels?
For example, when I load my first view the elements on the screen load correctly, but as soon as I move to another view everything (in all my views) gets pushed up 10 pixels.
The following code is my method in my AppDelegate that I call when the button is pressed. GameState is my singleton class for tracking the ViewController.
- (void)gotoStartUp
{
StartUpController *myStartUp = [[StartUpController alloc] initWithNibName:@"StartUpController" bundle:nil];
[self setStartUpController:myStartUp];
[myStartUp release];
GameState *myVC = [GameState currentGameState];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
//[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
[myVC.currentViewController.view removeFromSuperview];
[self.window addSubview:[startUpController view]];
[UIView commitAnimations];
}
I then have another ViewController and View that I switch to based on the selected button using a similar method like the following:
- (void)gotoNewGame
{
NewGameController *myStartUp = [[NewGameController alloc] initWithNibName:@"NewGameController" bundle:nil];
[self setNewGameController:myStartUp];
[myStartUp release];
GameState *myVC = [GameState currentGameState];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
//[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:window cache:YES];
[myVC.currentViewController.view removeFromSuperview];
[self.window addSubview:[newGameController view]];
[UIView commitAnimations];
}
I then use these methods to navigate between my views (I have 5 of them set up like this).
I've been trying to get my arms around views and view controllers and putting them all together. I finally felt like I was making some progress, but I don't have any idea where to start on this one. Keep in mind that I'm brand new to Objective-C (and development as well).
Here's what the screen looks like on the initial load (everything looks right):
Here's what the screen looks like after I've switch views and come back to the same screen:
Thanks in advance for your help! I thought I better post my Application Delegate header file as well:
#import <UIKit/UIKit.h>
@class StartUpController, FightController,PrepareArenaController, NewGameController, LoadGameController;
@interface ArenaAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
IBOutlet StartUpController *startUpController;
IBOutlet LoadGameController *loadGameController;
IBOutlet NewGameController *newGameController;
IBOutlet PrepareArenaController *prepareArenaController;
IBOutlet FightController *fightController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet StartUpController *startUpController;
@property (nonatomic, retain) IBOutlet LoadGameController *loadGameController;
@property (nonatomic, retain) IBOutlet NewGameController *newGameController;
@property (nonatomic, retain) IBOutlet PrepareArenaController *prepareArenaController;
@property (nonatomic, retain) IBOutlet FightController *fightController;
- (void)gotoStartUp;
- (void)gotoGameInstructions;
- (void)gotoLoadGame;
- (void)gotoNewGame;
- (void)gotoPrepareArena;
- (void)gotoFight;
@end