IOS orientation change does not work either UIDeviceOrientationDidChangeNotification not received

I am very new to iOS and I am desperate to get orientation changes working in my application. Having studied here what I am doing:

In my application, I have a NavigationController managing seven subclasses of the UIViewController.

On the Project Overview tab, I activated all 4 device orientations.

Each subclass of the UIViewcontroller has an xib file, all xib files have "autoresist subviews".

Subclasses of UIViewController have:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight ); } 

They also have:

 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 

and

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

implemented using NSLog (...) statements (never printed, the debugger also never introduces these methods).

Also I tried to use:

  [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; BOOL getOrientationUpdates = [[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications]; NSLog(@"will receive orientation notifications: %@", getOrientationUpdates?@ "YES":@"NO"); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

from

-(void)orientationChanged: (NSNotification*) notification { NSLog(@"orientationChanged"); }

and

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] removeObserver:self]; respectively.

when i do beginGeneratingDeviceOrientationNotifications etc. in the AppDelegate method - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions , orientationChanged: is called once at startup, but I never turn the device again when I do this in one of the subclasses of the UIViewController, which it never not called!

So far, all I want to achieve is to receive orientation notifications for rotation of UIImageView and UIImage (without any layout changes in different orientations).

 UIDeviceOrientation o = [UIDevice currentDevice].orientation; 

always returns UIDeviceOrientationPortrait

I might have missed something in the docs or in stackoverflow, but I obviously can't figure out what I need to do / add to make it work in my setup. I am also completely new to stackoverflow, so I hope that my post does not violate any platform agreements.

Any help / advice is appreciated. Thank you very much!

EDIT: getOrientationUpdates is always YES, which seems strange to me, since a notification callback selector is never called when I rotate it!

EDIT: in my AppDelegate didFinishLaunchingWithOptions I do:

  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.regScreenController = [[RegistrationScreenController alloc] initWithNibName:@"RegistrationScreenController" bundle:nil]; navCtrl = [[UINavigationController alloc]initWithRootViewController:self.regScreenController]; [navCtrl setNavigationBarHidden:YES]; self.window.rootViewController = self.regScreenController; [self.window addSubview:navCtrl.view]; [self.window makeKeyAndVisible]; return YES; 
+4
source share
1 answer

See if you self.window.rootViewController to your AppDelegate's didFinishLaunchingWithOptions : method, because if you add only subvisors to the window, a notification about the orientation change does not work.

+5
source

Source: https://habr.com/ru/post/1413504/


All Articles