Forum Archive

Fading images at load

rb

Hi I’m trying to load in an image using ui.imageView then setting the alpha to 0.0 and then using ui.animate to alter that alpha to a non zero value. I can’t get this to gradually fade however - the alpha just jumps after the specified time.
What am I doing wrong here? This simple solution has worked fine for me previously for buttons etc.
I’m going for a gradually blending slideshow effect.

cvp

@rb try this

import ui
iv = ui.ImageView()
iv.frame = (0,0,400,400)
v = ui.View()
v.frame = iv.frame
v.background_color = (1,1,1,0)
iv.add_subview(v)
iv.present('sheet')
iv.image = ui.Image.named('test:Peppers')
def anim():
    v.background_color = (1,1,1,1)  
ui.animate(anim,5) 
rb

Thankyou - that’s masking an image with a colour and altering the alpha of the colour - isnt there a way to gradually alter an imageViews alpha over time?

cvp

@rb try

import ui
from objc_util import *
iv = ui.ImageView()
iv.frame = (0,0,400,400)
ObjCInstance(iv).alpha = 0
iv.present('sheet')
iv.image = ui.Image.named('test:Peppers')
def anim():
    ObjCInstance(iv).alpha = 1
ui.animate(anim,5) 
rb

Thanks that’s exactly what I’m after!

mikael

@rb, if you do a lot of little animations, I will once again plug the scripter lib. You can pip install it.