AddSubview with "animation"

Hi,

I’m using a a subview that I add on top of my current view to present some controls.

I can show and hide the subview nicely but I’d like to fade it in/out and maybe bluring the parent view.

Can I do that using AddSubview?

Almost.

First you need to make the subview completely transparent, then add subview and finally animate Alpha
Note: UIKitLib is a constant referring to “uikit.framework” that is used in Jason King’s iOSKit.

//Before AddSubView
Declare Sub setAlphaValue Lib UIKitLib selector "setAlpha:" (id As ptr, value As CGFloat)
setAlphaValue ctrl.handle, 0.0

//Here your code to add subview
...

//Now animate
subview.AnimateAlpha(1.0, 0.3)

Then add a function in the subview:

Private Sub TransformAlphaBlock() declare sub setAlphaValue lib UIKitLib selector "setAlpha:" (id as ptr, value as CGFloat) setAlphaValue self.id, TransformToAlpha End Sub

And a property TransformToAlpha as Double

And another function that is called to animate

[code]Public Sub Animatealpha(alpha As Double, duration as Double)

TransformToAlpha = alpha
Dim animations as new iOSBlock (AddressOf TransformAlphaBlock)

Declare sub animateWithDuration_ lib UIKitLib selector “animateWithDuration:animations:completion:” _
(id as ptr, duration as Double, animations as ptr, completion as ptr)

animateWithDuration_ self.Handle, duration, Animations.handle, nil

End Sub
[/code]

How do you create a subview?

Dim cc as new iOSContainerControl

cc is a subview.

or

Dim vSubView as new JasonsView

JasonsView is a iOSVIew

A minor fix to one of the functions:

Changed self.id -> self.handle

Private Sub TransformAlphaBlock() declare sub setAlphaValue lib UIKitLib selector "setAlpha:" (id as ptr, value as CGFloat) setAlphaValue self.handle, TransformToAlpha End Sub

Weirdly enough I get an exception when executing:

Declare sub animateWithDuration_ lib UIKitLib selector “animateWithDuration:animations:completion:”

I’ve tried other selectors but id does not help. This is the exception:

*** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[XOJContainerControl animateWithDuration:animations:completion:]: unrecognized selector sent to instance 0xc85c620’

Yes, you had to replace self.id with self.handle

[quote=348839:@JrmieLeroy]

[code]Public Sub Animatealpha(alpha As Double, duration as Double)

TransformToAlpha = alpha
Dim animations as new iOSBlock (AddressOf TransformAlphaBlock)

Declare sub animateWithDuration_ lib UIKitLib selector “animateWithDuration:animations:completion:” _
(id as ptr, duration as Double, animations as ptr, completion as ptr)

animateWithDuration_ self.Handle, duration, Animations.handle, nil

End Sub
[/code][/quote]

The above code had an error, this is the correct code:

[code]Public Sub Animatealpha(alpha As Double, duration as Double)

TransformToAlpha = alpha
Dim animations as new iOSBlock (AddressOf TransformAlphaBlock)

Declare sub animateWithDuration_ lib UIKitLib selector “animateWithDuration:animations:completion:” _
(id as ptr, duration as Double, animations as ptr, completion as ptr)

Declare Function NSClassFromString Lib “Foundation” (clsName As CFStringRef) As ptr
Dim classPtr as ptr = NSClassFromString(“UIView”)

animateWithDuration_ classPtr, duration, Animations.handle, nil

End Sub
[/code]

Voila!

:slight_smile:

Perfect, Thank you so much!

It is not easy with the declares, well sometime it is, but I’m learning slowly more and more thanks to you and other nice people.