iPad、iphone 横竖屏的切换事件 两个View切换

ios屏幕旋转注意事项

有些人说写了旋转事件,怎么不执行,有一点要注意哦

直接把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];
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值