奇怪的iPad屏幕问题 - 在视图之间移动推动控制?

时间:2010-07-04 04:38:01

标签: iphone objective-c ipad uiviewcontroller

当我使用UIView开始,设置和提交动画切换视图时,我遇到了一个奇怪的问题。

由于某种原因,当我更改视图时,它会将屏幕上的元素向上推大约10个像素?

例如,当我加载第一个视图时,屏幕上的元素加载正确,但是一旦我移动到另一个视图,所有内容(在我的所有视图中)都被推高了10个像素。

以下代码是我在AppDelegate中按下按钮时调用的方法。 GameState是我用于跟踪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];
}

然后我使用类似的方法,根据所选按钮切换到另一个ViewController和View:

- (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];
}

然后我使用这些方法在我的视图之间导航(我有5个像这样设置)。

我一直试图抓住视图并查看控制器并将它们放在一起。我终于觉得我在取得一些进展,但我不知道从哪里开始。请记住,我是Objective-C(以及开发)的新手。

这是初始加载时屏幕的样子(一切看起来都正确): alt text http://www.freeimagehosting.net/uploads/4e2eaffa69.png

以下是我切换视图并返回同一屏幕后屏幕的样子:

alt text http://www.freeimagehosting.net/uploads/c22ae63885.png

提前感谢您的帮助! 我想我最好发布我的Application Delegate头文件:

#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

1 个答案:

答案 0 :(得分:1)

尝试此代码(来自here)。它帮助了我

- (void)viewWillAppear:(BOOL)animated {
    // to fix the controller showing under the status bar
    self.view.frame = [[UIScreen mainScreen] applicationFrame];
}