iphone - 检测iphone方向的最佳方法

标签 iphone ios xcode4

我正在制作一个应用程序,我可以根据用户是否以纵向或横向模式移动他的 iPhone 来更改按钮布局。我认为放置我的代码的最佳位置是

-(BOOL) shouldautorotatetointerfaceorientation

但是这有两个主要问题

  1. 当页面加载时,应该至少调用 3 次autorotatetointerfaceorientation。我只想执行一次我的代码。

  2. 即使我使用 Modal segue 从 viewController1 (page1) 移动到 viewController2 (page2) 并在 page2 上旋转我的 iPhone,它仍然会调用我的 viewcontroller1 中的自动代码。那很奇怪。

无论如何,放置基于方向的图标的最佳位置是什么?

最佳答案

方法的唯一目的

-(BOOL) shouldautorotatetointerfaceorientation

用于确定支持哪些方向。

如果您希望对旋转执行自定义操作,那么您希望实现一个或两个方法

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration

关于iphone - 检测iphone方向的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8826912/

相关文章:

objective-c - 将静态库导入自定义通用框架

ios - 如何在 swift3 中增加 String.Index?

javascript - Google map v3 未在 iPad 上加载 - 按钮加载但 map 只是蓝色

c++ - 在 Xcode 4 中使用 ccache

objective-c - 获取 UIGestureRecognizer 的 UITouch 对象

ios - 创建自定义协议(protocol),其方法像 tableview 的方法或 uislider 的方法一样被调用

cocoa - 如何从 Xcode 4 中的实体创建用户界面?

ios - MKMapView 上的引脚注释上的触摸事件

iphone - 我需要在 TableView 中创建自定义的基于图像的accessoryType 的示例代码

iphone - 从应用程序在保管箱中创建文件夹