UIView Transitions - UBogun/Xojo-iosLib GitHub Wiki
After block and spring animations, transitions are another type of animation you can perform on every iOS control. They come in two flavors: transitions which perform a pseudo 3D-operation like flipping and transitions between two different views which must both be subviews of the same superview.
And then there‘s another system animation to remove a view from its superview which I include in this section too.
Transitions on Views
Now, the third animation parameter that was discussed in part I comes into play: UIViewAnimationTransition. Its values are:
Name | Effect |
---|---|
None | No transition |
FlipFromBottom | The view is flipped from its lower side to its "backside" |
FlipFromLeft | The view is flipped from its left side to its "backside" |
FlipFromRight | The view is flipped from its right side to its "backside" |
FlipFromTop | The view is flipped from its upper side to its "backside" |
CrossDissolve | The original view fades |
CurlDown | A "pages" animation starting at the top |
CurlUp | A "pages" animation starting at the bottom |
Although flipping seems to turn around the view, it is not mirrored.
You can combine these transitions with property animations, but again not every type of UIView will react fully. Here are the transition animations, partly combined with a property animation (and usually reversed, so only one for bottom and left and none for top and right):
TransitionWithFrame on gradient rectangle: FlipFromBottom
TransitionWithAlpha on gradient rectangle: FlipFromLeft
TransitionWithColor on iOSVIew: CurlDown
TransitionWithTransform on gradient rectangle: CrossResolve
The transform property was created by
dim angle as double = 300
dim transform as CGAffineTransform = TransformExtension.CGAffineTransformScale (canvas1.view.transform, 0.5)
transform =TransformExtension.CGAffineTransformRotate (transform, angle.DegreeToRadian)
Please note that because of the absence of a real rotation method, an angle of 300 degree clockwise results in a 60 degree rotation counterclockwise.
If you want to attain a continuous rotation, define a completion block that starts another 180 degrees rotation.
If you want to change the rotation angle, pass a negative value.
With the exception of the MoveTo animation, you will find convenience methods for transitions very much like for the former animations, now with an added Transition parameter and the usual optional properties Seconds and Curve:
- TransitionWithAlpha (NewAlpha As Double, Transition as AppleView.UIViewAnimationTransition)
- TransitionWithBackgroundColor (NewColor As Color, Transition as AppleView.UIViewAnimationTransition)
- TransitionWithBounds (Width As Double, Height As Double, Transition as AppleView.UIViewAnimationTransition)
- TransitionWithFrame (NewFrame As Xojo.Core.Rect, Transition as AppleView.UIViewAnimationTransition)
- TransitionWithScale (XScale as Double, opt. YScale as Double, Transition as AppleView.UIViewAnimationTransition)
- TransitionWithTransform (aTransform As CGAffineTransform, Transition as AppleView.UIViewAnimationTransition)
- TransitionWithBlock (Block As AppleBlock / iOSBlock, Transition as AppleView.UIViewAnimationTransition): for custom or multiple transitions.
Additionally, a
- Transition (Transition as AppleView.UIViewAnimationTransition) convenience method is available in the iOSControlExtension module that passes an empty block to the AppleView class
- TransitionWithDuration (id as ptr, duration as Double, animations as ptr, completion as ptr, options as uinteger) method.
Transitions to Views
In the Transitions description, I talked about that while the flip transitions give the idea of flipping a view to its backside, no real backside exists. Well, truth is you can simulate one. The
- TransitionToView (newView as AppleView, Transition as AppleView.UIViewanimationTransition, options As AppleViewAnimationOption, seconds As Double = 0.2, Curve as AppleView.UIViewAnimationCurve = UIViewAnimationCurve.EaseInEaseOut)
is intended mainly for views containing subviews.
It works on the SuperView(!) of the view you are addressing and performs a Transition just like above while it removes the view you are running this method on from its superview and replaces it with its subview.
In other words: While you flip a view, you can replace its before-shown subview with another view for its back side. Be aware that the initial view is removed. If you want to reuse it, you need to buffer it in a local property.
If both views are already part of your view hierarchy, you can include the UIViewAnimationOptionShowHideTransitionViews option in the options parameter to simply hide or show them – the initial view will not be removed.
Because of this method aiming mainly for subview replacing, you will most probably want to call it on the AppleView object of a control, which means by addressing the
- ViewTransition (fromview as appleview, toView as Appleview, Transition as UIViewAnimationTransition, options as AppleViewAnimationOption, Seconds as Double = 0.2, Curve as UIVIewAnimationCurve = uiviewanimationcurve.EaseInEaseOut, completion as appleblock = nil)
method that is available for every Xojo control under its View As AppleView property.
TransitionToView gradient rectangle replaced by a new view with a gray background: FlipFromRight
Animated View Removals
Finally, there's a PerformSystemAnimation class method you theoretically can use to remove several views at once. Theoretically, because I have not figured out how to use it yet.