iOS Question IOS 16 Rotation problem

lymey

Active Member
Licensed User
Longtime User
Hi, I understand that Apple has changed the way we can rotate a page. The following code of Erels has worked fine up until IOS 16.x.
Is there a new API to control rotation in the same way?

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'Public variables can be accessed from all modules.
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page
   Private Page2 As Page
End Sub

Private Sub Application_Start (Nav As NavigationController)
   'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.RootPanel.LoadLayout("1")
   NavControl.ShowPage(Page1)
   Page2.Initialize("Page2")
   Page2.RootPanel.Color = Colors.Red
End Sub

Sub Page1_Click
   NavControl.ShowPage(Page2)
End Sub

Sub Main_ShouldAutoRotate As Boolean
   If Page2.Visible = True Then
     Return False 'Don't auto rotate if Page2 is visible
   Else
     Return True
   End If
End Sub


#if OBJC
@end
@interface UINavigationController (B4IResize)

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

#End If
 

Filippo

Expert
Licensed User
Longtime User
Hi, I understand that Apple has changed the way we can rotate a page. The following code of Erels has worked fine up until IOS 16.x.
Is there a new API to control rotation in the same way?

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'Public variables can be accessed from all modules.
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page
   Private Page2 As Page
End Sub

Private Sub Application_Start (Nav As NavigationController)
   'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.RootPanel.LoadLayout("1")
   NavControl.ShowPage(Page1)
   Page2.Initialize("Page2")
   Page2.RootPanel.Color = Colors.Red
End Sub

Sub Page1_Click
   NavControl.ShowPage(Page2)
End Sub

Sub Main_ShouldAutoRotate As Boolean
   If Page2.Visible = True Then
     Return False 'Don't auto rotate if Page2 is visible
   Else
     Return True
   End If
End Sub


#if OBJC
@end
@interface UINavigationController (B4IResize)

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

#End If

The best is you create each layout with 2 alignment, one for vertical and one for horizontal alignment.
 
Upvote 0

lymey

Active Member
Licensed User
Longtime User
Currently there is no workaround for this. You can set the whole app orientation and nothing else.
The IOS 16 release notes suggest the following, is there anyway to incorporate that into b4i?

UIKit​

New Features​

  • iOS apps can now request rotation using [UIWindowScene requestGeometryUpdate:errorHandler:] and providing a UIWindowSceneGeometryPreferencesIOS object containing the desired orientations. (95229615)

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

lymey

Active Member
Licensed User
Longtime User
The best is you create each layout with 2 alignment, one for vertical and one for horizontal alignment.
I appreciate what you are saying. The problem is that the app only has to be in Landscape mode for a specific set of circumstances, the rest of the time it is in portrait mode. The user experience will become frustrating/annoying if what they see on screen changes, so I'm trying to avoid two versions of every layout. I suppose if I prevent rotation from portrait mode I would need to somehow detect orientation change of the device to display a landscape layout.
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
The IOS 16 release notes suggest the following, is there anyway to incorporate that into b4i?
Unfortunately it is like Erel wrote, there is no solution at the moment.
I have solved it for my apps so, I show a message when the orientation is wrong. So the user knows that he should turn the device around.

1677010548645.png

1677010557136.png
 
Upvote 0
Top