1. 监测设备横竖屏两种方式:
1)通过 UIApplication
[UIApplication sharedApplication]statusBarOrientation] 的值为 UIDeviceOrientationLandscapeRight 或者 UIDeviceOrientationLandscapeLeft 表示横屏
值为 UIDeviceOrientationFaceUp 或者
UIDeviceOrientationFaceDown 时表示竖屏
2)利用 UIDevice 类的 orientation 特性
UIDevice *nowDevice = [UIDevice currentDevice];
if(nowDevice.orientation == UIDeviceOrientationLandscapeRight || nowDevice.orientation == UIDeviceOrientationLandscapeLeft)
UIDeviceOrientationPortrait /UIDeviceOrientationPortraitUpsideDown 表示竖屏
2. 设置全屏
self.wantsFullScreenLayout=YES;
3. 隐藏屏幕状态栏
[[UIApplication sharedApplication]setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
设置为YES,则表示不隐藏
4. 屏幕全屏切换实现,利用UIKit.framework库中的 UIResponder 类的(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 实现
代码如下所示:
// UIDevice *nowDevice = [UIDevice currentDevice];
// if(nowDevice.orientation == UIDeviceOrientationLandscapeRight || nowDevice.orientation == UIDeviceOrientationLandscapeLeft)
if([[UIApplication sharedApplication]statusBarOrientation] == UIDeviceOrientationLandscapeRight || [[UIApplication sharedApplication]statusBarOrientation] == UIDeviceOrientationLandscapeLeft)
{
//横屏
if(self.wantsFullScreenLayout)
{
[[UIApplication sharedApplication]setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];//设置不隐藏状态栏
self.myPlayerView.frame = CGRectMake(0, 0, self.myControlView.frame.size.width, self.view.frame.size.height - self.myControlView.frame.size.height);
self.myControlView.hidden = NO;//设置控制功能view显示
self.wantsFullScreenLayout = NO;//设置不要全屏
}
else
{
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
self.myControlView.hidden = YES;
self.myPlayerView.frame = CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width);
self.wantsFullScreenLayout = YES;
}
}
else
{
//树屏
if(self.wantsFullScreenLayout)
{
[[UIApplication sharedApplication]setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
self.myPlayerView.frame = rect;//CGRect rect = self.myPlayerView.frame;
self.myControlView.hidden = NO;
self.wantsFullScreenLayout = NO;
}
else
{
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
self.myControlView.hidden = YES;
self.myPlayerView.frame = self.view.frame;
self.wantsFullScreenLayout = YES;
}
}