检测iphone方向的最佳方法

Sam*_*m B 0 iphone ios xcode4

我正在创建一个应用程序,我可以根据用户是否在纵向和横向模式下移动iphone来更改按钮布局.我认为放置代码的最佳位置是

-(BOOL) shouldautorotatetointerfaceorientation
Run Code Online (Sandbox Code Playgroud)

但是有两个主要问题

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

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

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

Pen*_*One 5

该方法的唯一目的

-(BOOL) shouldautorotatetointerfaceorientation
Run Code Online (Sandbox Code Playgroud)

是确定支持哪些方向.

如果您希望对旋转执行自定义操作,则需要实现其中一个或两个方法

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
Run Code Online (Sandbox Code Playgroud)