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

时间:2010-04-16 12:17:32

标签: iphone

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

2 个答案:

答案 0 :(得分:9)

取决于您想要做什么,

在您的活动视图控制器类中实现some of these methods

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

或者您的app委托中的some of these methods

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

或听取some of these local notifications

  • UIApplicationWillChangeStatusBarFrameNotification
  • UIApplicationDidChangeStatusBarFrameNotification
  • UIApplicationWillChangeStatusBarOrientationNotification
  • UIApplicationDidChangeStatusBarOrientationNotification

答案 1 :(得分:5)

您可以使用:

   [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

   [[NSNotificationCenter defaultCenter] addObserver:self
      selector:@selector(yourMethod:)
      name:@"UIDeviceOrientationDidChangeNotification" object:nil];