iOS Question Detect panel at 180º

angel_

Well-Known Member
Licensed User
Longtime User
I am trying to detect when the panel is rotated 180º but it does not detect it

B4X:
Sub Button2_Click
    Panel1.Rotation = Panel1.Rotation + 90
    
    Log("New angle: " & Panel1.Rotation)
    CurrentRotation(Panel1.Rotation)
End Sub

Sub CurrentRotation(Angulo As Int)
    Select Angulo
        Case 0
            Log("Angle: " & Panel1.Rotation)
        Case 90
            Log("Angle: " & Panel1.Rotation)
        Case 180, -180    '<--- NO DETECTED
            Log("Angle: " & Panel1.Rotation)
        Case 270, -90
            Log("Angle: " & Panel1.Rotation)
    End Select
End Sub
 

Attachments

  • Rotar.zip
    110.4 KB · Views: 167

roumei

Active Member
Licensed User
Adding values to Panel1.Rotation leads to rounding errors and thus the .Rotation value might for example be 89 instead of 90. Use a global variable (0,1,2,3) for the orientation. No need for your Sub CurrentRotation but it will work nonetheless.

B4X:
' Process_Globals
Private iPanel1Rot As Int = 0

Sub Button2_Click
    
    iPanel1Rot = iPanel1Rot + 1
    If iPanel1Rot > 3 Then iPanel1Rot = 0
    
    Select Case iPanel1Rot
        Case 1
            Panel1.Rotation = 90
        Case 2
            Panel1.Rotation = 180
        Case 3
            Panel1.Rotation = 270
        Case Else
            Panel1.Rotation = 0
    End Select
    
    CurrentRotation(Panel1.Rotation)
    
End Sub
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
Adding values to Panel1.Rotation leads to rounding errors and thus the .Rotation value might for example be 89 instead of 90. Use a global variable (0,1,2,3) for the orientation. No need for your Sub CurrentRotation but it will work nonetheless.

B4X:
' Process_Globals
Private iPanel1Rot As Int = 0

Sub Button2_Click
 
    iPanel1Rot = iPanel1Rot + 1
    If iPanel1Rot > 3 Then iPanel1Rot = 0
 
    Select Case iPanel1Rot
        Case 1
            Panel1.Rotation = 90
        Case 2
            Panel1.Rotation = 180
        Case 3
            Panel1.Rotation = 270
        Case Else
            Panel1.Rotation = 0
    End Select
 
    CurrentRotation(Panel1.Rotation)
 
End Sub
Thanks, I can't detect it this way either

B4X:
Sub Button2_Click
    iPanel1Rot = iPanel1Rot + 1
    If iPanel1Rot > 3 Then iPanel1Rot = 0
   
    Select Case iPanel1Rot
        Case 1
            Panel1.Rotation = 90
        Case 2
            Panel1.Rotation = 180
        Case 3
            Panel1.Rotation = 270
        Case Else
            Panel1.Rotation = 0
    End Select
   
    Log("New angle: " & Panel1.Rotation)

    CurrentRotation(Panel1.Rotation)
End Sub

Sub CurrentRotation(Angulo As Int)
    Select Angulo
        Case 0
            Log("Angle: " & Panel1.Rotation)
        Case 90
            Log("Angle: " & Panel1.Rotation)
        Case 180, -180    '<--- NO DETECTED
            Log("Angle: " & Panel1.Rotation)
        Case 270, -90
            Log("Angle: " & Panel1.Rotation)
    End Select
End Sub
 
Upvote 0

roumei

Active Member
Licensed User
Why do you want to detect it with Panel1.Rotation if you've got the global variable for this?
If it is necessary, a work-around might be to round the angle like this before the Select Angulo:
B4X:
Angulo = Round(Angulo / 90) * 90
 
Upvote 0
Top