下面是一些代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; //返回yes表示支持屏幕的旋转哦,如果为no,你的view将不会跟随屏幕旋转 } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { //屏幕将要转到时执行 if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) { //如果是模向时执行啥事件 // 重新加载一个Nib文件 //[[NSBundle mainBundle] loadNibNamed:@"LoginViewLandscape" owner:self options:nil]; NSLog(@"cccccccccccccccccccc"); }else { //如果是纵向时执行啥事件 // 重新加载一个Nib文件 // [[NSBundle mainBundle] loadNibNamed:@"LoginView" owner:self options:nil]; NSLog(@"kkkkkkkkkkkkkkkkkkkkk"); } } -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { //屏幕转动结束后触发,跟上面的差不多,也可以调用这个 if(fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) { //如果向左方向,显示提示框 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"弹窗" message:@"左横屏" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:nil]; [alert show]; [alert release]; } }