iOS Question How to RotateView in B4I

winjiadh

Active Member
Licensed User
Longtime User
Search in the Forum, I found two ways to rotate a picture。
one:
Add a B4X View,and use the SetRotationAnimated(3000,180)
Private imageview1 As B4XView
B4X:
Private imageview1 As B4XView
Private Sub ImageView1_Click
    imageview1.SetRotationAnimated(3000,180)
End Sub
two:
use OBJC
B4X:
Sub RotateView(View As View, DurationMs As Int, Angle As Double)
   Dim no As NativeObject = Me
   no.RunMethod("rotateView:::", Array(View, DurationMs, Angle * cPI / 180))
End Sub

#If OBJC
- (void) rotateView:(UIView*)view :(int)DurationMs :(double)angle {
   [UIView animateWithDuration:DurationMs / 1000.0 delay:0.0f
     options:UIViewAnimationOptionCurveEaseOut animations:^{
  view.transform = CGAffineTransformMakeRotation(angle);
  } completion:^(BOOL finished) {

  }];
}
#End If

'Example:
RotateView(Button1, 1000, 180)
https://www.b4x.com/android/forum/threads/animations.46156/
Erel post: You will need a timer if you want to rotate it multiple times.
How to add the timer?

But the rotation of the picture only happens once. I don't know if I add parameters, I can rotate the picture 360 degrees, or continue to rotate.

In B4A can use the AnimationPlus, like this
B4X:
Private Ani As AnimationPlus
Private ImgAndroid As ImageView
Sub Button1_Click
    Ani.InitializeRotateCenter("Ani", 360, 315, ImgAndroid)
    Ani.PersistAfter=True 
    Ani.Duration = "10"
    Ani.Start(ImgAndroid)
End Sub

thanks
 
Top