• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iphone - 设备方向 - 以合法方式更改(iOS 4.0+)

[复制链接]
菜鸟教程小白 发表于 2022-12-13 09:04:54 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我的应用程序有导航栏,其中第一个屏幕返回"is"方向,第二个屏幕根据用户在第一个屏幕中选择的内容设置为某个方向。从第 2 个屏幕返回第 1 个屏幕后,如果用户手持设备为纵向但界面为横向,则第 1 个屏幕设置为横向。发生这种情况是因为

(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation 

仅在更改设备方向后调用。

我想检查什么是设备方向 atm 并将界面方向设置为此。 试过了:

//1st method:
UIViewController *rotateTheScreen = [[UIViewController alloc]init];
[self presentModalViewController:rotateTheScreen animated:NO];
[self dismissModalViewControllerAnimated:NO];
[rotateTheScreen release];

//2nd method:
UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;

//3rd method:
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

第一个表现得很奇怪,除了从界面方向=横向和设备方向=横向返回之外,旋转所有情况(这是一个错误,他旋转到横向) 第二次检查界面,就像名字所说的那样,但对我的问题不起作用 据我所知,第三个是私有(private)的,Apple 拒绝使用它的应用程序。



Best Answer-推荐答案


看看这个thread . 基本上,没有办法强制设备方向让您的应用程序获得 Apple 的批准。

简而言之,该方法存在,但它是 UIDevice 类的未记录方法。

[[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight animated:YES];

这会给出一个编译器警告,您可以使用一个类别来消除它。

@interface UIDevice (MyAwesomeMethodsThatAppleWillNeverAllowMeToUse)
    -(void)setOrientationUIInterfaceOrientation)orientation animatedBOOL)animated;
    -(void)setOrientationUIInterfaceOrientation)orientation;
@end

另外,有人说您可以使用 performSelector 间接调用这些方法来绕过 Apple 的静态代码分析,您可以在评论 here 中阅读。 .

关于iphone - 设备方向 - 以合法方式更改(iOS 4.0+),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7280464/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap