iOS Question Question regarding getting Device Orientation

walterf25

Expert
Licensed User
Longtime User
Hi All, I am trying to convert an Android App I have finished some time ago, specifically the following part:
B4X:
        Case se.TYPE_ORIENTATION
            magValues = Values
            Log("magValues(0): " & magValues(0))
            Log("magValues(1): " & magValues(1))
            Log("magValues(2): " & magValues(2))
            
            Dim rotationMatrix(0) As Float
            If accValues.Length = 0 Or magValues.Length = 0 Then Return
            Dim R(9), I(9) As Float
            Dim success As Boolean = sm.RunMethod("getRotationMatrix", Array(R, I, accValues, magValues))
            If success Then
                Dim orientation(3) As Float
                sm.RunMethod("getOrientation", Array(R, orientation))
                '''Log("orientation: " & (orientation(0) * 180 / cPI + 360) Mod 360))
'''                Log("orientation(0): " & orientation(0))
'''                Log("orientation(1): " & orientation(1))
'''                Log("orientation(2): " & orientation(2))
                orientation2 = (orientation(0) * 180) / (cPI + 360)
                '''Log("orientation: " & orientation2)
            End If
            '''Log("values(0): " & Values(0) & " values(1): " & Values(1) & " values(2): " & Values(2))
    End Select

I use this code to figure out if the orientation is less or equals to zero and the following code, to draw a line inside a square which moves up and down, sort of like a bubble Level.

B4X:
    If orientation2 <= 0 Then
    canvasY.DrawLine(0, Normalize(thetaX, 90, 0), canvasY.Bitmap.Width, Normalize(thetaX, 90, 0), Colors.green, 2dip)
    limit = Normalize(thetaX, 90, 0)
    Else
    canvasY.DrawLine(0, (Abs(Normalize(thetaX, 200, 100))+100), canvasY.Bitmap.Width, (Abs(Normalize(thetaX, 200, 100))+100), Colors.Green, 2dip)
    limit = (Abs(Normalize(thetaX, 200, 100))+100)
    End If

The part I am concerned about is the first part of the code above, is there a way to get the orientation from the iOS device just like with the Android code above?

Thanks,
Walter
 

walterf25

Expert
Licensed User
Longtime User
Upvote 0
Top