0

I want to be notified when the orientation of the device changes. I've setup a test method that's suppose to receive the notification. I'm trying several different observers to achieve that, and none of them are working. Why isn't testMethod being fired?

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    // register for orientation change notification

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

    [[NSNotificationCenter defaultCenter] addObserver: self
                                         selector: @selector(testMethod)
                                             name: UIApplicationWillChangeStatusBarOrientationNotification
                                           object: nil];
    [[NSNotificationCenter defaultCenter] addObserver: self
                                         selector: @selector(testMethod)
                                             name: UIApplicationDidChangeStatusBarOrientationNotification
                                           object: nil];
}

- (void)testMethod
{
    NSLog(@"phone was rotated");
}
zakdances
  • 22,285
  • 32
  • 102
  • 173

3 Answers3

1

I accidentally had the rotation lock engaged on my phone. Always test on more than one phone!

zakdances
  • 22,285
  • 32
  • 102
  • 173
0

You need to use the Orientation notification, which is UIDeviceOrientationDidChangeNotification. Do not put it inside the @"UIDeviceOrientationDidChangeNotification" because you dont know the actual content of the constant which is UIDeviceOrientationDidChangeNotification. It appears you are using a view controller. You should use willRotateToInterfaceOrientation:duration: and didRotateFromInterfaceOrientation:

J2theC
  • 4,412
  • 1
  • 12
  • 14
  • I'm trying -(void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration { NSLog(@"rotated"); } but its still not be fired – zakdances Aug 09 '12 at 18:11
0

end of the bool type something set the orientation .write return yes in all end of the view ..orientation in potrait and landscape mode takeplace

Bajaj
  • 859
  • 7
  • 17