2

Apple 会接受以下代码吗?

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

当我写这篇文章时,我看到以下警告:

警告:“UIDevice”可能不会响应“-setOrientation:”

那么我该怎么做才能以编程方式设置 iPhone 的方向呢?

4

4 回答 4

1

写完之后[[UIDevice currentDevice] set ];,你找到选项了setOrientation吗?绝对是私有 API。不要使用它。

于 2010-12-27T11:17:08.863 回答
1

你应该阅读这个 Stack Overflow 问题的答案它有很多关于如何处理方向以及如何处理它的代码片段的长时间讨论。

于 2010-12-27T11:21:25.823 回答
0

不,Apple 拒绝使用此代码的应用程序。

于 2010-12-27T11:11:27.640 回答
0

只需在您使用它的 .h 或 .m 文件的类别中声明该方法。

@interface UIDevice (MyPrivateNameThatAppleWouldNeverUseGoesHere)

-(void) setOrientation:(UIInterfaceOrientation)orientation;

@end

但苹果也拒绝使用此代码的应用程序。因此,将其用于呼叫定向方法的解决方案..它工作正常

UIViewController *viewController = [[UIViewController alloc] init];

[viewController setModalPresentationStyle:UIModalPresentationCurrentContext];

viewController.view.frame = CGRectZero;

[self presentModalViewController:viewController Animation:NO];

[自我dismissModalViewControllerAnimated:否];

[viewController 发布];

对不起,如果有任何错误。我是 iphone 的新手... :)

于 2013-03-23T08:34:57.963 回答