admin管理员组文章数量:1026989
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(iphoneipaditouch)开发 之 屏幕旋转
版权声明:本文标题:IOS(iphone,ipad,itouch)开发 之 屏幕旋转 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/IT/1687913992a156813.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论