方向改变触发的方法

Sam*_*man 13 iphone ios

这是一种在iOS设备方向改变时运行方法的方法吗?

我想只更改屏幕上的某些对象方向,而不是其他方向.

我使用的代表是什么

干杯 - 一个新手

Bri*_*ang 32

取决于你想要做出反应:

如果在旋转之前,从UIViewController 覆盖:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
 // do something before rotation
}
Run Code Online (Sandbox Code Playgroud)

如果你想在轮换后执行某些操作:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
 // do something after rotation
}
Run Code Online (Sandbox Code Playgroud)

参考:

http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/willRotateToInterfaceOrientation:duration:

  • 这些方法已被弃用. (4认同)

dra*_*ard 6

UIDevice 帖子 UIDeviceOrientationDidChangeNotification

UIApplication帖子UIApplicationWillChangeStatusBarOrientationNotificationUIApplicationDidChangeStatusBarOrientationNotification并且每个都有一个相关的委托回调.

UIViewController 如果视图控制器是由窗口管理的控制器层次结构的一部分,则接收由UIDevice通知触发的多个与方向相关的调用.

如果您已经在使用UIViewController,请实现一些与方向相关的方法,否则请注册UIDevice通知.最重要的UIViewController方法是shouldAutorotateToInterfaceOrientation因为如果返回NO其他人则不会被调用.