你的位置:
首页
>
IT圈
>
IOS(iphone,ipad,itouch)开发 之 屏幕旋转
IOS(iphone,ipad,itouch)开发 之 屏幕旋转
关于IOS开发中屏幕旋转的问题.
看过很多大牛的文章,都写过类似的,这里我只写一下常用的几个函数的具体用法.
首先是
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
该函数的功能字面意思,是否允许旋转.
具体用法如下:
在ViewController.m里重写相关方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight) //如果屏幕方向等于左横屏 或者 又横屏时
return YES; //返回true,既允许旋转.
else
return NO; //不允许旋转
}
变量interfaceOrientation指触发时间后,当前屏幕方向.
关于4个方向:
UIInterfaceOrientationLandscaprLeft:左横屏
UIInterfaceOrientationLandscapeRight:右横屏
UIInterfaceOrientationPortrait:正常竖屏
UIInterfaceOrientationPortraitUpsideDown:反向竖屏
有了控制旋转的函数,接下来就是为不同方向定义不同的响应方法.
要用到
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
例如我们希望当屏幕是左横屏的时候弹出一个提示窗口,可以这么做:
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if(fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"弹窗"
message:@"左横屏"
delegate:self
cancelButtonTitle:@"关闭"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
如果我们需要控制空间的位置,也只需要写在这个函数里.
还有几个相关函数,我还没看,等看了再给大家解释下.
IOS(iphone,ipad,itouch)开发 之 屏幕旋转
关于IOS开发中屏幕旋转的问题.
看过很多大牛的文章,都写过类似的,这里我只写一下常用的几个函数的具体用法.
首先是
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
该函数的功能字面意思,是否允许旋转.
具体用法如下:
在ViewController.m里重写相关方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight) //如果屏幕方向等于左横屏 或者 又横屏时
return YES; //返回true,既允许旋转.
else
return NO; //不允许旋转
}
变量interfaceOrientation指触发时间后,当前屏幕方向.
关于4个方向:
UIInterfaceOrientationLandscaprLeft:左横屏
UIInterfaceOrientationLandscapeRight:右横屏
UIInterfaceOrientationPortrait:正常竖屏
UIInterfaceOrientationPortraitUpsideDown:反向竖屏
有了控制旋转的函数,接下来就是为不同方向定义不同的响应方法.
要用到
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
例如我们希望当屏幕是左横屏的时候弹出一个提示窗口,可以这么做:
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if(fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"弹窗"
message:@"左横屏"
delegate:self
cancelButtonTitle:@"关闭"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
如果我们需要控制空间的位置,也只需要写在这个函数里.
还有几个相关函数,我还没看,等看了再给大家解释下.
与本文相关的文章
- IOS(iphone,ipad,itouch)开发 之 屏幕旋转
- ios5.1.1完美越狱中文教程ipad3,ipad2,ipad,iphone3,iphone4,iphone4s
- ipad,iphone 屏幕旋转支持
- ipad没有苹果电脑怎么更新
- ipad怎么做mac的屏幕
- ipad怎么变笔记本扩屏
- 6 个最值得使用的 iPad 数据恢复软件
- iPad远控Windows解决方案
- 如何通过 5 种有效方法将锁定的 IPad 恢复出厂设置?
- 苹果ipad黑屏了开不了机是什么原因?2种解决办法分享!
- iPad能装Android系统,我错了,原来iPad真的能装Windows和macOS系统!
- XDISPLAY:将IPAD或安卓平板,变成WINDOWS(MAC)系统的显示器副屏
- ipad显示portal服务器获取不,苹果portal认证失败原因合集
- iPad、iphone、Windows PC间文件共享、互传
- ipad mini2 12.5.4成功降级 10.3.3
- iPad不断重启怎么办?
- Windows+iPad扩展屏幕-随航功能