一个简单的例子:
1.注册通知:
//设备方向消息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(GuomobWallonDeviceOrientationChange) name:
UIDeviceOrientationDidChangeNotification object:nil];
2.消息响应
-(void)GuomobWallonDeviceOrientationChange
{
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
//if((orientation==UIDeviceOrientationPortrait)||(orientation==UIDeviceOrientationPortraitUpsideDown))
if(orientation==UIDeviceOrientationPortrait)
{
// NSLog(@"竖屏***************");
imageview.frame=CGRectMake(0, 0, rect_screen.size.width, rect_screen.size.height);
btnReqAd.frame=CGRectMake((rect_screen.size.width-300)/2, 40, 300, 60);
btnReadPoint.frame=CGRectMake((rect_screen.size.width-300)/2, 105, 300, 40);
btnWritePoint.frame=CGRectMake((rect_screen.size.width-300)/2, 150, 300, 40);
btncheckPoint.frame=CGRectMake((rect_screen.size.width-300)/2, 195, 300, 40);
btnupdatePoint.frame=CGRectMake((rect_screen.size.width-300)/2, 240, 300, 40);
}
else if((orientation==UIDeviceOrientationLandscapeLeft)||(orientation==UIDeviceOrientationLandscapeRight))
{
// NSLog(@"横屏***************");
imageview.frame=CGRectMake(0, 0, rect_screen.size.height, rect_screen.size.width);
btnReqAd.frame=CGRectMake((rect_screen.size.height-300)/2, 40, 300, 60);
btnReadPoint.frame=CGRectMake((rect_screen.size.height-300)/2,105, 300, 40);
btnWritePoint.frame=CGRectMake((rect_screen.size.height-300)/2, 150, 300, 40);
btncheckPoint.frame=CGRectMake((rect_screen.size.height-300)/2, 195, 300, 40);
btnupdatePoint.frame=CGRectMake((rect_screen.size.height-300)/2, 240, 300, 40);
}
}