iOS Question B4xView SetRotationAnimated behaves differently on b4i

Jack Cole

Well-Known Member
Licensed User
Longtime User
I'm trying to use this to rotate a panel 360 degrees. Works fine on Android. On iOS it seems to rotate to the closest. If you try to rotate to 350, it will rotate CCW 10 degrees. Android rotates CW to 350.

On b4a I do the following and it works as expected.
B4X:
Sub SwiftButton1_Click
    stimback.SetRotationAnimated(2000, 360)
End Sub

I can make it work on b4i doing the following, but I don't like it much.
B4X:
Sub SwiftButton1_Click
    stimback.SetRotationAnimated(1000, 180)
    Sleep(1000)
    stimback.SetRotationAnimated(1000, 360)
End Sub

Anyway, if this is intended behavior, I will just work around it. If not, I just wanted to let you know in case it needs to be fixed.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is how the underlying rotation feature works. You can make B4A behave like B4i with this code:
B4X:
Sub RotateViewShortestArc (v As B4XView, Duration As Int, Target As Int)
   Dim Rotation As Int = v.Rotation
   Dim dx As Int = (Target - Rotation) Mod 360
   If dx > 180 Then
       dx = -(360 - dx)
   Else if dx < -180 Then
       dx = 360 + dx
   End If
   v.SetRotationAnimated(Duration, Rotation + dx)
End Sub

However I guess that you should keep using your code.
 
Upvote 0
Top