有些人说写了旋转事件,怎么不执行,有一点要注意哦
直接把view add成为window的subview的controller才会触发
还有就是controller不能release掉
例如:
直接把view add成为window的subview的controller才会触发,我记得官方文档里有写到
还有就是controller不能release掉
例如:
XXXController *c = [[XXXController alloc] init];
[window addSubview:c.view];
[c release];
下面是一些代码:
- (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];
}
}