ActionScript: can Tweener scale upwards instead of downwards? - actionscript

I'm using the ActionScript Tweener from here
I have a scaling animation on one of my images but I can't seem to get it to scale (enlarge) upwards instead of downwards
Tweener.addTween(myImage,
{
scaleX: 1.5;
scaleY: 1.5;
transition: "linear";
}
I have tried modifying my flex component holding the image, but the animation seems to ignore the dimensions of the image container. Any way I can do this using Tweener but without any other external components?

Got it. Changed the container to a HGroup and set VerticalAlign to center
<s:HGroup verticalAlign="bottom">
<s:Graphic mouseOver="enlargeImg(event)" mouseOut="shrinkImg(event)" ../>
<s:Graphic ../>
</s:HGroup>

Related

How to rotate a view in place after transform as been applied?

I'm using a variant of this code to slighty rotate a UIButton about its center:
CGFloat jiggleAngle = (-M_PI * 2.0) * (1.0 / 64.0);
self.transform = CGAffineTransformRotate(self.transform, jiggleAngle);
This code generally works as expected and rotates the button in-place, about 12 degrees counter-clockwise. However, this only works if I do not reposition the button inside my layoutSubviews method. If I do any repositioning of the button at all from its initially laid-out location, the attempt to rotate above results in the button's disappearance. If the angle I choose for rotation is an exact multiple of 90 degrees, the rotation works somehow even after a move in layoutSubviews.
I understand that my button's transform is being altered in layoutSubviews and this results in the subsequent weirdness when I attempt to rotate it with the above code. I have currently worked around this problem by placing the button I wish to rotate inside another UIView and then moving that view around as desired, but I'd like a better solution that doesn't require redoing my screen layouts.
How can I adjust/alter my button's transform after a move, so that this rotation code continues to work as expected?
The problem you are facing is that a view's frame is "undefined" if it's transform isn't the identity transform.
What you should do is use the view's center property to move it around. That works even if you've changed it's transform.
You can also apply a rotation to the view's layer instead of the view (although be aware that the layer transform is a CATransform3D, a 4x4 transformation matrix instead of a 3x3, so you need different methods to manipulate it.)

Applying just the scale component of a CGAffineTransform to a UIView

I have a UIView to which various scale and rotation CGAffineTransforms have been applied, in response to touch screen gestures.
When a scale operation completes, I want to adjust the bounds of the view to the new size, then have view to re-draw itself at a scale of 1.0, while keeping all other components of the transform the same.
To adjust the bounds of the view, I'm using:
self.myView.bounds = CGRectApplyAffineTransform(self.myView.bounds, self.myView.transform);
To "undo" the scale transform, I'm trying this:
self.myView.transform = CGAffineTransformConcat(self.myView.transform, CGAffineTransformMakeScale(1, 1));
then calling [myView setNeedsDisplay] to get the view to redraw itself.
However this does not produce the desired results and when a rotate transform is applied, the above code seems to cause what looks like a sideways translation transform to be applied too.
What's the cleanest way to "undo" just a scale transform and have the view redraw at 1:1 with all other transforms remaining intact?
I am handling something similar, and what I do is store the separate components in another struct (scale, rotation, translation). That way you can easily recreate the transform again (be careful about the order of your operations though).
One thing though: I suggest that you don't change the bounds and instead just apple a scale operation to the transform. This will avoid some potential unneeded layouts. All of this stuff can be handled purely with the transform property. The way you are doing it now is not going to change anything since applying a scale of 1 is a no-op. If you scaled up the view by 2, you would need to scale by 0.5 to get back to the original. Or, as I said above, store all the components and recreate it from the identity matrix (matrix math is fast, don't worry about that).
Save your scale values in a variable and then, try changing CGAffineTransformMakeScale(1, 1) into
CGAffineTransformMakeScale(1/totalScaleWidth, 1/totalScaleHeight)

UIView's content blurry when I center it

I have UIView that isn't big as the whole screen and I want it to appear in the middle of the screen. I did that with the following code:
self.dialogView.center = CGPointMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0);
Unfortunately, when I center it like that, UIView's content appears blurry.
I've fixed it with this:
self.dialogView.center = CGPointMake(self.view.bounds.size.width / 2.0 + 0.5, self.view.bounds.size.height / 2.0);
Now UIView's content appears as it should :)
Can you tell me why that content becomes blurry and why I need to add 0.5 to the left position offset?
The new center is causing the origin of the control's view to fall on a half-pixel, like { 20.5, 20.5 }. Since the screen can't draw only half a pixel, the rendering engine attempts to get the same effect by diffusing the image as best it can, resulting in blurry images.
You need to make sure all your views' origins are whole numbers.
well i think thats due to how the UIView is being placed on the pixel grid of the screen. if you think about it on regular screens (72 px/inch), 0.5 points means 0.5 pixels which would probably cause what you see... thats my theory at least :P

Correcting blurry text after a CGAffineTransformMakeScale

I have multiple views with many UILabels on the views. (all constructed in Interface Builder).
I am then trying to create a "smaller" replica of my view when you pinch the screen.
To do this I apply:
view.transform = CGAffineTransformMakeScale(.5, .5);
and then I also adjust the frame of view.
The problem is that after the transformation, the text in all of my UILabels becomes "blurry". It doesn't stay pixel perfect as it is in full-scale view.
Is there a way to increase the pixelation of the labels after the transformation?
Applying a transform to a UIView or CALayer merely scales the rasterized bitmap of that layer or view. This can lead to blurriness of the resulting UI element, because they aren't re-rendered at that new scale.
If you really want your text or images to be crisp at the new scale factor, you're going to need to manually resize them and cause them to redraw instead of applying a transform. I described one way that I did this with a UIView hosted in a UIScrollView in this answer.
You might be able to create a single method that traverses your view hierarchy for your one main view, recursively reads each subview's frame, scales that down, and then forces a redraw of its contents. Transforms are still great to use for interactive manipulation or animation, but you can then trigger a full manual scaling and redraw at the end of the manipulation or animation.

minimize window animation, but for iOS?

I have an overlay help text in a UIView that I would like to animate up to a button in the navigationbar, in a way similar to the minimize window animation on Mac OS X.
I can do the basic animations of fading opacity and resizing windows, but this one is difficult.
Any clues how to do this kind of animation with a UIView?
There are two effects for OSX that you can set for that (if I'm understanding this right), the Scale and Genie effects. To mimic the scale one, you need to animate the scale, opacity, and positions.
Example using implicit animation:
view.layer.transform = CATransform3DMakeScale(0.2, 0.2, 1);
view.layer.position = CGPointMake(yournavbarspot.x, yournavbarspot.y);
view.layer.opacity = 0.0f;
To do the genie effect, you'd do the same thing and also alter the shape of the view as it animates. I'm not sure if you can change the geometry of a UIView, so the closest thing I can think of would be to create a mask that you alter the geometry of using UIBezierPaths.

Resources