iOS Question Pulse button

emexes

Expert
Licensed User
You could set up a timer that cycles the button's size, position and/or background color, eg one-time setup like:

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
 
    Dim Button1 As Button
    Dim Button1Timer As Timer
 
    Dim Button1X As Int
    Dim Button1Y As Int
    Dim Button1SizeX As Int
    Dim Button1SizeY As Int
    Dim Button1ThrobX As Int
    Dim Button1ThrobY As Int
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)

    Root = Root1
    Root.LoadLayout("MainPage")
    Sleep(0)    'give Button1 chance to initialize
 
    Button1SizeX = Button1.Width
    Button1SizeY = Button1.Height
    Button1X = Button1.Left
    Button1Y = Button1.Top
    Button1ThrobX = Min(Button1SizeX, Button1SizeY) * 0.05    'relative throb size 5%
    Button1ThrobY = Button1ThrobX    'same throb for both axes
 
    Button1Timer.Initialize("Button1", 1000 / 15)    '15 frames per second
    Button1Timer.Enabled = True

End Sub

and then animate button like:

B4X:
Sub Button1_Tick

    Dim Phase As Double = Sin(DateTime.Now / (2000 / 3.14159 / 2))    'cycle time (throb period?) 2 seconds (2000 ms)
 
    Dim ThrobX As Int = Button1ThrobX * Phase
    Dim ThrobY As Int = Button1ThrobY * Phase
 
    Button1.Left = Button1X + ThrobX
    Button1.Top = Button1Y + ThrobY
    Button1.SetSize(Button1SizeX - 2 * ThrobX, Button1SizeY - 2 * ThrobY)
 
    'bonus ?
    'Dim RotatableButton1 As B4XView = Button1
    'RotatableButton1.Rotation = Phase * 10

End Sub
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
Lol no law (that I know of) against having multiple pulsing buttons eg:

B4X:
    Button2.Left = Button2X + ThrobX
    Button2.Top = Button2Y + ThrobY
    Button2.SetSize(Button2SizeX - 2 * ThrobX, Button2SizeY - 2 * ThrobY)

and even with some in opposite phase eg:

B4X:
    Button3.Left = Button3X - ThrobX
    Button3.Top = Button3Y - ThrobY
    Button3.SetSize(Button3SizeX + 2 * ThrobX, Button3SizeY + 2 * ThrobY)
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Lol no law (that I know of) against having multiple pulsing buttons eg:

????
? B4X
1.gif


???
 
Upvote 0
Top