iOS Question Shake Animation for Imageview?

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Anyone was create the same shake effect in iOS?

similar this one for B4A
B4X:
Sub Globals
   Private EditText1 As EditText
   Private shake As Animation
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1") 'Includes EditText1
   shake.InitializeTranslate("", -10dip, 0, 10dip, 0)
   shake.RepeatCount = 5
   shake.RepeatMode = shake.REPEAT_REVERSE
   shake.Duration = 50
End Sub

Sub Activity_Click
   shake.Start(EditText1)
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Never use the Animation library. It is not required.

Cross platform solution:
B4X:
Sub ShakeView (View As B4XView, Duration As Int)
   Dim Left As Int = View.Left
   Dim Delta As Int = 20dip
   For i = 1 To 4
       View.SetLayoutAnimated(Duration / 5, Left + Delta, View.Top, View.Width, View.Height)
       Delta = -Delta
       Sleep(Duration / 5)
   Next
   View.SetLayoutAnimated(Duration/5, Left, View.Top, View.Width, View.Height)
End Sub

Sub Page1_Click
   ShakeView(TextField1, 500)
End Sub

Add a reference to iXUI.
 
Upvote 0
Top