Open trhtkv opened 4 years ago
I think you can update this to use the notification: UIDeviceOrientationDidChangeNotification
instead of UIApplicationDidChangeStatusBarOrientationNotification
This code file is a UIView
, so it won't have access to viewWillTransitionToSize:withTransitionCoordinator
which is a UIViewController method.
I tested making that change in an old app, and it appears to be ok at suppressing the warning and logic still seems to be ok with a quick test.
An alternative would be to expose a new method that you'd have to tie into your UIViewController callback, which seems more cumbersome.
Another option is to remove all this logic, as I don't think you really want it rotating anymore on modern iOS.
- (void)registerForNotifications {
#if !TARGET_OS_TV && !TARGET_OS_MACCATALYST
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(statusBarOrientationDidChange:)
name:UIDeviceOrientationDidChangeNotification object:nil];
#endif
}
- (void)unregisterFromNotifications {
#if !TARGET_OS_TV && !TARGET_OS_MACCATALYST
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
#endif
}
#if !TARGET_OS_TV && !TARGET_OS_MACCATALYST
- (void)statusBarOrientationDidChange:(NSNotification *)notification {
UIView *superview = self.superview;
if (!superview) {
return;
} else {
[self updateForCurrentOrientationAnimated:YES];
}
}
#endif
'UIApplicationDidChangeStatusBarOrientationNotification' is deprecated: first deprecated in iOS 13.0 - Use viewWillTransitionToSize:withTransitionCoordinator: instead.