免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2442 | 回复: 1
打印 上一主题 下一主题

iphone一些知识,去掉StatusBar,横屏,重力感应,自动切换横竖,开机画面横屏,开机画 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-12 21:07 |只看该作者 |倒序浏览

iphone一些知识,去掉StatusBar,横屏,重力感应,自动切换横竖,开机画面横屏,开机画面横屏。










http://www.cnblogs.com/APTX4869/archive/2011/02/24/1963527.html
1,去掉StatusBar

在info.plist添加UIStatusBarHidden设置Boolean,设置为YES.

2,横屏

继续在info.list中添加UIInterfaceOrientation 设置UIInterfaceOrientationLandscapeRight

3,重力感应

AppDelegate继承UIAccelerometerDelegate协议,并实现

  1. // Implement this method to get the lastest data from the accelerometer

  2. - (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration {

  3. //Use a basic low-pass filter to only keep the gravity in the accelerometer values{}
复制代码
  1. - (void)applicationDidFinishLaunching:(UIApplication *)application {


  2. }
复制代码
添加

  1. //Configure and start accelerometer

  2. [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kAccelerometerFrequency)];

  3. [[UIAccelerometer sharedAccelerometer] setDelegate:self];
复制代码
就可以实现重力感应

4,自动切换横竖。
  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation //支持横 竖转动
  2. {

  3. return YES;
  4. }
  5. - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration //当发生旋转 时
  6. {
  7. f(self.interfaceOrientation==UIInterfaceOrientationPortrait||self.interfaceOrientation==UIDeviceOrientationPortraitUpsideDown)
  8. {
  9. //横 转向 竖
  10. }
  11. }
  12. - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation //旋转 完成
  13. {          if(self.interfaceOrientation==UIInterfaceOrientationPortrait||self.interfaceOrientation==UIDeviceOrientationPortraitUpsideDown)
  14. {
  15. //当前是在竖屏模式
  16. }
  17. }
复制代码
横屏之间切换
  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation //支持横 竖转动

  2. {

  3. if (interfaceOrientation == UIInterfaceOrientationLandscapeRight )

  4. {

  5. return YES;

  6. }

  7. else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)

  8. {

  9. return YES;

  10. }

  11. return NO;

  12. }
复制代码
/////////////////////////////////////////////////////////////

以下未经过测试

使用重力感应,判断手机的方向,然后设定[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight,以及UIInterfaceOrientationPortrait,就可以做到根据不同的手机方向弹出横屏还是竖屏的对话框了,包括对话框上包含输入框的键盘也可以自动旋转了

/////////////////////////////////////////////////////////////

5,开机画面横屏

Default-LandscapeLeft.png
Default-LandscapeRight.png
Default-Portrait.png
Default-PortraitUpsideDown.png

论坛徽章:
0
2 [报告]
发表于 2012-03-12 21:07 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP