Animated stretch of an image frame (iPhone) - iphone

So I'm trying to animate an image stretching from a zero width to full size while fading in. The fade in comes across fine, but for whatever reason the thing appears at the full frame at the start of the animation, instead of growing as the alpha effect happens. My code is as follows:
[UIView beginAnimations:#"FadeButtons" context:nil];
[UIView setAnimationDuration:.9];
[UIView setAnimationDelay:0.300];
batteryLife.alpha = 1;
batteryLife.frame = CGRectMake(40, 71, 240, 128);
[UIView commitAnimations];
Any advice on changing a frame in an animated fashion? I don't want to scale the entire image, I want to "unveil" it. Thanks.

Perhaps the frame is already that size before beginAnimations? Try setting the frame immediately before beginAnimations to the smaller size, like batteryLife.frame = CGRectMake(40, 71, 0, 128);

Related

IOS UIView animation

- (void)showLabelAnimation
{
[UIView beginAnimations:#"animationID" context:nil];
[UIView setAnimationDuration:1];
//original rectangle is (0,0,100,50)
//and I want to change label to (100,100,200,100)
label.bounds = CGRectMake(100, 100, 200, 100);
label.frame = CGRectMake(100, 100, 200, 100);
[UIView commitAnimations];
}
It works well, but I just wondering why I have to set both bounds and frame of label. They seem like the same thing.
Can anyone explains this for me?
Thanks in advance.
[Edit in Nov 3rd]
Thanks for your help, but when I remove the setbounds line, it doesn't work well, the label will be large immediately but move to new position by animation. The resize animation does not show up.
That's the real thing which wonder me.
You should only have to set the frame. Bounds should update on its own.
Edit for additional help:
Labels don't scale; changing the frame of it changes where the text is placed, but the size of the text does not scale this way.
However, you can enable the UILabel's adjustsFontSizeToFitWidth property to 'yes' and then before you run the animation, set the font size to be at its largest before running it. As it scales, the font size should change to fit and achieve the effect you're looking for.
The frame is the rectangle relative to the view's parent. The bounds is the rectangle relative to itself.
The animation should work without the line
label.bounds = CGRectMake(100, 100, 200, 100);
That code is working for me
[UIView animateWithDuration:1
animations:^(void) {
self.leLabel.frame = CGRectMake(labFrame.origin.x,
labFrame.origin.y + 100.0f, labFrame.size.width + 50.0f, labFrame.size.height);
}];
For what you want to do, you should only set the frame.
If I change frame by bound in the previous code I will get a very strange behaviour.
So my guess is the reason you need to set both is because you've tested first with bound and added frame after to correct the error introduced by the setting of bound.

Animate size of a UIView around center point

I have a UIView which I want to grow from it's center when a user touches it. The problem is that when animating it the view expands left and then moves to the right, whereas I want it to expand to the left and right, while keeping the center point the same.
This is the code I have at the moment:
[UIView animateWithDuration:1 animations:^(void) {
[view setFrame:CGRectMake(-10, 0, 320, view.frame.size.height)];
}];
I didn't think it was going to be difficult to do this, but it seems it is. Short of animating it manually with a timer I have no idea how to get it to expand from it's center.
I am not quite sure why it's working for you in a weird manner. Did you alter the anchorPoint property in any way? Otherwise it should grow from center.
Does doing
CGRect newFrame;
newFrame = CGRectInset(view.frame, -10, -30);
[UIView animateWithDuration:1 animations:^(void) {
view.frame = newFrame;
}];
also give you the same result? What about this?
[UIView animateWithDuration:1 animations:^(void) {
view.transform = CGAffineTransformScale(view.transform, 1.1, 1.1);
}];
Try the code given by #Deepak Danduprolu and also don't forgot to UnCheck the "Use AutoLayout" checkbox in the show file inspector window of the storyboard.
It works for me.
Just offset the X,Y position of the view. Lets say you're DECREASING both the width and height of the frame by 20 points: you should then ADD 10 points to both the X and Y position of the frame.

iPhone: How to resize a png file during an animation

Is there any way to resize (in my case increase the width) of an PNG file in an animation? This would need to result into a distortion of the original PNG (in my case, I try to get the PNG fatter).
My code so far is:
pageShadow = [UIImage imageNamed:#"pageshadow.png"]; // load our image resource
pageShadowView = [[UIImageView alloc] initWithImage:pageShadow];
[UIView beginAnimations:#"shadowMove" context:nil]; // Begin animation
[UIView setAnimationDuration:4.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//[pageShadowView setFrame:CGRectMake(0, 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];
[UIView commitAnimations];
But I can't think of a command to increase the width of my PNG. I guess this is not possible as long as it is confined to an UIView, right? I'd be grateful for any suggestions of how to tackle this problem. Thanks, and sorry if this is really obvious or basic.
to do what you want you probably want to add a transform to the view.
try something like
[pageShadowView setTransform:CGAffineTransformMakeScale (2, 1)];

iPhone effect comment box

I've just used Instagram application. I like the effect when I click on comment.
When you click "comment" you'll see a fade in view for insert the comment text.
How can I implement something like this?
Here two screenshot's:
Set a UIAnimation. Start the animation with the alpha of the view at 0, and then end the animation with the alpha of that view to 1, and commit the animation. And voila, you have a view that fades in.
It's easy. Create your view. When the user clicks the button, set the alpha of that view to 0 and set the size to smaller than your final size, etc.
lets say your view is called myView. you'd write:
myView.alpha = 0;
myView.frame = CGRectMake(50, 50, 100, 100);
[self.view addSubVew: myView];
[UIView beginAnimations:#"View Fade" context:nil];
[UIView setAnimationDuration: .25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
and then you set the alpha to 1 and increase the size of the view
myView.alpha = 1
myView.frame = CGRectMake(25, 25, 200, 200);
and then you commit the animations
[UIView commitAnimations];
It's something like that, i wrote it off the top of my head so I apologize for any syntax errors or anything. But that's pretty much how it's done.

UIView Animation iPhone (obtaining information on the frame dynamically)

I have a UIView called goalBar which is being animated by increasing the size of the frame according to a float value called destination:
CGRect goalBarRect = CGRectMake(0, 0, destination, 29);
[UIView beginAnimations:#"goal" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:2.0f];
goalBar.frame = goalBarRect;
[UIView commitAnimations];
The animation works perfectly and the rectangular view increases its width over the course of the animation (from 0 to the value for destination).
However, I wish to be able to extract the values for the frame of the UIView being animated (i.e. goalBar) as the animation takes place. By that I mean that I wish to place the value of the width for the animated frame in a separate UILabel so that the user sees a counter that provides the width of the UIView as it's being animated.
Any help on how to do the above would be gratefully received.
How about observing the frame property of the view. So that you get callbacks when it changes.
See Key-Value Observing.
I've looked into this and it seems that it is not possible to get updates on the state of the components being animated during the UIView animation process.