当接口在Iphone中旋转时,有没有办法调用函数?

wol*_*ine 0 iphone

当我的界面旋转时,我想调用某些功能.我该怎么做这些动作?

ken*_*ytm 9

取决于你想做什么,

在活动视图控制器类中实现其中一些方法:

  • -willRotateToInterfaceOrientation:duration:
  • -willAnimateRotationToInterfaceOrientation:duration:
  • -didRotateFromInterfaceOrientation:

或者您的app代理中的某些方法:

  • -application:willChangeStatusBarOrientation:duration:
  • -application:didChangeStatusBarOrientation:

或者听一些本地通知:

  • UIApplicationWillChangeStatusBarFrameNotification
  • UIApplicationDidChangeStatusBarFrameNotification
  • UIApplicationWillChangeStatusBarOrientationNotification
  • UIApplicationDidChangeStatusBarOrientationNotification


gam*_*gul 5

你可以用这个:

   [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

   [[NSNotificationCenter defaultCenter] addObserver:self
      selector:@selector(yourMethod:)
      name:@"UIDeviceOrientationDidChangeNotification" object:nil];
Run Code Online (Sandbox Code Playgroud)