0

我有这个代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation) )
{
    [[NSBundle mainBundle] loadNibNamed:@"ChatViewController-landscape" owner:self options:nil];

}else {

    [[NSBundle mainBundle] loadNibNamed:@"ChatViewController" owner:self options:nil];

}
}

我在 if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation) 行中设置了一个断点。但是第一次它没有进入那行代码。如果我转动手机,那个时间和随后的方法被调用。我怎样才能调用那个方法第一次?

4

1 回答 1

0

I think for the first time you will have to check the orientation on viewdidload and then load the nib file accordingly, you can create a single method that can be called from willRotateToInterfaceOrientation and viewDiD load for that

[[UIDevice currentDevice] orientation] this will give current orientation

于 2012-07-05T10:14:00.580 回答