IOS编程的方向支持一种肖像(portrait)和风景模式landscape。Portrait(肖像)模式是确实的模式。当我们看照片或者视频的时候,风景模式是一种更好地选择 缺省的upside-down portrait 模式是不支持的。

1 定义ios APP支持的方向

定下面的函数,用于支持程序支持的方向
-(NSUInteger) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll ;
}  

2 当方向改变时更新视图

-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    CGRect timeFrame = self.timeLabel.frame ;
    float viewHeight = self.view.frame.size.height ;
    float viewWidth = self.view.frame.size.width ;
    
    float fontsize = 30.0f ;
    BOOL hideButton = YES  ;
    
    if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
        fontsize = 30.0f ;
        timeFrame.origin.y = (viewHeight /2 ) - timeFrame.size.height ;
       timeFrame.size.width =(viewHeight) ;
    }
    else {
        hideButton = NO ;
        timeFrame.origin.y = (viewHeight /2 ) - timeFrame.size.height ;
       timeFrame.size.width = viewWidth ;
    }
    
    [self.modeButton setHidden:hideButton];
    [self.timeLabel setFont:[UIFont boldSystemFontOfSize:fontsize]];
    [self.timeLabel setFrame:timeFrame] ;
 
}