iOS canvas image blank after switching to another app then back to app

I was testing my app on my device. I noticed on one view that has a canvas which shows an image when I switch apps (swipe up and over and choose another app I have open) then come back to my app, the canvas image disappears. Is there something I could be missing? Of note, the image in this canvas does a little animation with the use of a timer. The animation is finished and the timer is stopped when I try the switch-switch back and I notice this. I have several other canvases that don’t seem to be affected. It was only on the ones with animation. Thoughts?

Here is the code in the timer

intYCoordStrike = intYCoordStrike + 2

if intYCoordStrike > canStrike1.Height then
  me.Mode = xojo.Core.Timer.modes.Off
  intYCoordStrike = 0
else
  if GameStrikes = 1 then
    canStrike1.Invalidate
  elseif GameStrikes = 2 then
    canStrike2.Invalidate
  elseif GameStrikes = 3 then
    canStrike3.Invalidate
  elseif GameStrikes = 4 then
    canStrike4.Invalidate
    
    'end game
    whichButton = HomeButton 'changes button
    canBtnSpinStop.Invalidate
    timerEndGame.Mode = xojo.Core.timer.Modes.Single 'timer stalls then shows the game over message
    
    pSpins = 0
    lblSpins.Text = "Sp: " + pSpins.ToText
    
  end if
end if

And here is the code in one of the canvases

'light purple background
g.FillColor = &cF1E9FC
g.FillRect(0, 0, me.Width, me.Height)

'darker border
g.FillColor = &c8843E2
g.FillRect(0, 0, me.Width, me.Width * 0.1) 'top
g.FillRect(0, 0, me.Width * 0.1, me.Height) 'left
g.FillRect(0, me.Height - me.Width * 0.1, me.Width, me.Width * 0.1) 'bottom
g.FillRect(me.Width - me.Width * 0.1, 0, me.Width * 0.1, me.Height) 'right

'strike card image
g.DrawImage(StrikeCardwhammy, 0, me.Height - intYCoordStrike, me.Width, me.Height)

Is the fact that I am zeroing out the intYCoordStrike variable in the timer when the animation is complete, and the canvas performs another Invalidate when going out and coming back into the app? Hence rendering the canvas’s y-coordinate back to the height of the canvas, which would make it appear invisible?

1 Like

Yes this seems to be the issue.
Also note that code executed in a timer might not be executed when the app is in the background.
The iOSView Activate event should fire when the app is brought back to the foreground, you could use that to perform some additional drawing by calling canvas.invalidate

Thank you for confirming. After some finagling I got this to work. Good tip about the view treating a switch out and back as an Activate. Didn’t know this!