关于设置iOS横竖屏的两种方式(转载)
2014-12-01 14:16
288 查看
iPhone的横屏竖屏针对iOS系统版本分为两种开发方式: 一种是iOS 6之前的使用模式 一种是iOS6的新模式. 两者的区别还是蛮大的.
1:iOS6之前通常使用 shouldAutorotateToInterfaceOrientation 来单独控制某个UIViewController的方向,需要哪个viewController支持旋转,只需要重写shouldAutorotateToInterfaceOrientation方法。如下示例,设置以后,屏幕被旋转时只支持横屏转换:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
iOS6之后使用如下两个方法控制自动旋转,分别是:
- (BOOL)shouldAutorotate
{
NSLog(@"让不让我旋转?");
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
NSLog(@"让我旋转哪些方向");
return UIInterfaceOrientationMaskAllButUpsideDown;
}
那么在自动旋转触发后,系统会自动调用另外两个方法:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
NSLog(@"将要旋转了?");
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
NSLog(@"如果让我旋转,我已经旋转完了!");
}
2:让程序第一次启动时立刻显示横屏还是竖屏的方式
如果是iOS6之前,下面设置的设备支持方向可在应用里面再被修改
如果是iOS6以后,会做为硬性条件,也就是如果设置了以后,应用里面的代码也无法再使用这个方向
3:传说中的私有API实现切换ViewController强制横屏的方式
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
[[UIDevice currentDevice] performSelector:@selector(setOrientation:)
withObject:(id)UIInterfaceOrientationLandscapeRight];
}
4:使用xib进行界面设计时,改变xib的横竖显示方式
1:iOS6之前通常使用 shouldAutorotateToInterfaceOrientation 来单独控制某个UIViewController的方向,需要哪个viewController支持旋转,只需要重写shouldAutorotateToInterfaceOrientation方法。如下示例,设置以后,屏幕被旋转时只支持横屏转换:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
iOS6之后使用如下两个方法控制自动旋转,分别是:
- (BOOL)shouldAutorotate
{
NSLog(@"让不让我旋转?");
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
NSLog(@"让我旋转哪些方向");
return UIInterfaceOrientationMaskAllButUpsideDown;
}
那么在自动旋转触发后,系统会自动调用另外两个方法:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
NSLog(@"将要旋转了?");
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
NSLog(@"如果让我旋转,我已经旋转完了!");
}
2:让程序第一次启动时立刻显示横屏还是竖屏的方式
如果是iOS6之前,下面设置的设备支持方向可在应用里面再被修改
如果是iOS6以后,会做为硬性条件,也就是如果设置了以后,应用里面的代码也无法再使用这个方向
3:传说中的私有API实现切换ViewController强制横屏的方式
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
[[UIDevice currentDevice] performSelector:@selector(setOrientation:)
withObject:(id)UIInterfaceOrientationLandscapeRight];
}
4:使用xib进行界面设计时,改变xib的横竖显示方式
相关文章推荐
- 【iOS开发-72】设置状态栏的两种方式、程序生命周期以及更好地理解几大类(对象)之间的关系
- iOS 关于使用xib创建cell的两种初始化方式
- 【iOS开发-72】设置状态栏的两种方式、程序生命周期以及更好地理解几大类(对象)之间的关系
- iOS 关于使用xib创建cell的两种初始化方式
- 关于搜索elasticsearch的数据条数大于10000的坑 max_result_window的两种设置方式
- 关于ios 里面碰到内存错误的两种设置
- iOS 关于使用xib创建cell的两种初始化方式
- 【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式
- iOS学习笔记14—设置顶部状态栏(State)的两种方式
- 关于IOS屏幕旋转的几个问题1.常规设置2.个别页面强制固定横竖屏
- iOS:关于UIView切角的两种实现方式
- iOS开发中App启动页和应用缩略图标的两种设置方式
- 关于调试-设置断点的两种方式:按下F9或者在行号左侧的灰色显示列单击即可,再次按下F9或者单击可取消断点
- 关于iOS中图片加载的两种方式的区别以及和内存的关系
- IOS上 关于状态栏的相关设置(UIStatusBar)(转载自shede333博客)
- iOS开发UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式
- 【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式
- 关于js中两种定时器的设置及清除(转载)
- 关于ios 里面碰到内存错误的两种设置
- python中package机制的两种实现方式(转载)