UIView显示错误的方向

时间:2010-12-19 10:26:09

标签: iphone uiview uiviewcontroller

在模拟器上一切正常,但在真正的iphone 3g上有bug。 我两次调用Splash Screen。第一次 - 好的,第二次看到错误:http://img413.imageshack.us/i/bugicu.png/

我该如何解决?

@interface iStateGameAppDelegate : NSObject 
{    
    UIWindow* window;
    UINavigationController* navigationController;
}

-(void) showSpalshScreen;
-(void) showSwitchViewController;

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@end

@implementation iStateGameAppDelegate


@synthesize window;
@synthesize navigationController;
- (BOOL) application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
    [self showSpalshScreen];
    [window makeKeyAndVisible];

    return YES;
}

-(void) showSpalshScreen
{

    SplashScreen* splashScreen = [[[SplashScreen alloc] initWithNibName:@"SplashScreen" bundle:[NSBundle mainBundle]] autorelease];
    [window addSubview:[splashScreen view]];

}

-(void) showSwitchViewController
{
    SplashScreen* splashScreen = [[[SplashScreen alloc] initWithNibName:@"SplashScreen" bundle:[NSBundle mainBundle]] autorelease];
    [window addSubview:[splashScreen view]];
}

- (void) dealloc
{
    [navigationController release];
    [window release];
    [super dealloc];
}

@interface SplashScreen : UIViewController {}
@end

@implementation SplashScreen

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad 
{
    [super viewDidLoad];
    NSTimer *timer = [[NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:NO] retain];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

- (void)timerFired:(NSTimer *)timer
{   
    [[UIApplication sharedApplication] setStatusBarHidden:FALSE];
    iStateGameAppDelegate* app = [UIApplication sharedApplication].delegate;
    [app showSwitchViewController];
    [[self view] removeFromSuperview];
    [timer invalidate];
    [timer release];
    timer = nil;
}

- (void)dealloc {
    [super dealloc];
}

1 个答案:

答案 0 :(得分:0)

  1. 确保正确设置了视图的委托。
  2. 您应该检查UIInterfaceOrientationLandscapeRightUIInterfaceOrientationLandscapeLeft