iOS Question ShouldAutoRotate not work in iOS 16

Filippo

Expert
Licensed User
Longtime User
Hi,

the ShouldAutoRotate function no longer works in iOS 16, how to solve the problem?
I found something here, but can not implement myself.

B4X:
Sub Main_ShouldAutoRotate As Boolean
    Log("Main_ShouldAutoRotate")
    If IsSetOrientation Then
        If DeviceOrientation = "Portrait" And OrientationModus = "Landscape" Then
            Return False
        else If DeviceOrientation <> "Portrait" And OrientationModus = "Portrait" Then
            Return False
        Else
            Return True
        End If
    Else
        Return False
    End If
End Sub

B4X:
#if OBJC
@end
@interface UINavigationController (B4IResize)

@end
@implementation UINavigationController (B4IResize)
- (BOOL)shouldAutorotate
{
  return [(NSNumber*)[B4IObjectWrapper raiseEvent:self :@"_shouldautorotate" :nil] boolValue];
}

#End If

#End Region
 

Filippo

Expert
Licensed User
Longtime User
I've tried several things but they didn't work on iOS 16.
There is a new API that allows you to explicitly rotate the screen. What exactly are you trying to do?
I have 2 layouts in my app, one for horizontal and one for vertical alignment.
Via the App-Setting the user can choose between the 2 alignments.
Therefore, the alignment should not change automatically. This has also worked well until iOS 15.
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
I've tried several things and none worked. No solution for now.
Hi Erel,

Apple writes here that from iOS-16 you can use the new ViewController "setNeedsUpdateOfSupportedInterface", but doesn't write how and doesn't give an example.
For some of my applications this feature is absolutely necessary, without it the functionality of the application is otherwise very limited.

Deprecations​

  • [UIViewController shouldAutorotate] has been deprecated is no longer supported. [UIViewController attemptRotationToDeviceOrientation] has been deprecated and replaced with [UIViewController setNeedsUpdateOfSupportedInterfaceOrientations].
    Workaround: Apps relying on shouldAutorotate should reflect their preferences using the view controllers supportedInterfaceOrientations. If the supported orientations change, use `-[UIViewController setNeedsUpdateOfSupportedInterface
 
Upvote 0
Top