set a UIImageView anchorPoint without changing the location in Interface Builder - iphone

In order to make an image appear from left to right, I am setting the anchorPoint like so:
myImageView.layer.anchorPoint = CGPointMake(0.0f, 1.0f);
then animating it:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
myImageView.transform = CGAffineTransformMakeScale(1.0, 1.0);
[UIView commitAnimations];
The animation works great, but by changing the image's anchorPoint, the image does not appear in the location where it was set in Interface Builder, it gets moved around quite a bit when that anchorPoint is set.
Does anybody know if there is a way to set the anchorPoint or accomplish this effect without changing the image's location in Interface Builder?
Thanks!

In ViewDidLoad: Just Initialise Your ImageView Frame:
[ImageView setFrame:CGRectMake(900, 0, 69, 39)];
and write this below code:
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionTransitionCurlDown
animations:^{
//animation code
ImageView.frame = CGRectMake(0, 0, 320, 345);
} completion:^(BOOL finished) {
//completion code
}];

Related

Animating self.view.window.frame change

I'm using animation with blocks and I'm trying to animate a change to my main window's frame.
Here is my code:
[UIView animateWithDuration:0.3f animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
self.view.window.frame = CGRectMake(0.0f, -20.0f, self.view.window.frame.size.width, self.view.window.frame.size.height+20);
}];
However it doesn't animate like self.view.frame changing or something else. It's just plain crap without animation.
Any ideas?
This is Wrong, Window is Fixed in FRAME And Bounds,
you cannot move Window, its top Root Container and has constant size, you should translate and transform your view only like this.
[UIView animateWithDuration:0.3f animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
self.view.frame = CGRectMake(0.0f, -20.0f, self.view.frame.size.width, self.view.frame.size.height+20);
}];

iOS - Animation effects - Image pop-in

I'd like to have an image in my iphone app "pop-in" on screen rather than just appearing. By "pop-in" I mean that it would grow from a small dot to its actual size. For reference, this is exactly the same as the "pop" animation effect in Keynote.
I'm completely new to iOS animations, so if someone could point me in the direction on the animation effects I would need to use, it would be greatly appreciated.
Thanks
Brian
UPDATE
I've added this code from the suggestions below. This works but it scales my image down, rather than up. I know that is because I have 0.01 as the transform scale size, but I would like to know how I can start out with an image of size 0.0 and scale up to 1. Is it just a matter to setting the size of my image to 0?
Thanks
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.2];
image.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
The effect you’re looking for is something like this:
// instantaneously make the image view small (scaled to 1% of its actual size)
view.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
// animate it to the identity transform (100% scale)
view.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
// if you want to do something once the animation finishes, put it here
}];
if you want something like Facebook does on liking any post then use this
-(void)animateButton:(UIButton *)sender{
UIButton * btn = (UIButton *)sender;
[UIView animateWithDuration:0.3/1.5 animations:^{
btn.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.4, 1.4); // scales up the view of button
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3/2 animations:^{
btn.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.7, 0.7);// scales down the view of button
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3/2 animations:^{
btn.transform = CGAffineTransformIdentity; // at the end sets the original identity of the button
}];
}];
}];}
just call this method when you want to animate the view
if you have text and image on the button and you just want to animate the image of the button then just replace "btn" with "btn.imageView" , this will just produce animation on the image view property of the button.
Hope it helps
All the best.
You have to animate the frame of the view, to shrink it from zero to the final state.
This can be done for example with UIView block animation.
So for example start with your view as an IBOutlet property self.myView with the final size and position, but set the hidden flag.
Then when you want it to appear use the following:
// Save old frame as final stater and set it to zero size for the start of the animation
// But keep the same center position, so it just grows and don't move around
CGRect oldFrame = self.myView.frame;
CGRect oldCenter = self.myView.center;
self.myView.frame = CGRectZero;
self.myView.center = oldCenter;
self.myView.hidden = NO;
NSTimeInterval duration = 0.3;
[UIView animateWithDuration:duration delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
// New position and size after the animation should be the same as in Interface Builder
self.myView.frame = oldFrame
}
completion:^(BOOL finished){
// You can do some stuff here after the animation finished
}];
Swift 2.0 version
view.transform = CGAffineTransformMakeScale(0.01, 0.01);
UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: { () -> Void in
// animate it to the identity transform (100% scale)
self.view.transform = CGAffineTransformIdentity;
}) { (finished) -> Void in
// if you want to do something once the animation finishes, put it here
}
For that you will have to use a simple UIView
Add the UIview to your current view.
- (void) initPopUpView
{
popup.alpha = 0;
popup.frame = CGRectMake (160, 240, 0, 0);
[self.view addSubview:popup];
}
- (void) animatePopUpShow
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
[UIView setAnimationWillStartSelector:#selector(initPopUpView)];
popup.alpha = 1;
popup.frame = CGRectMake (20, 40, 300, 400);
[UIView commitAnimations];
}

Animate two views like when you pass a phone call

I have made many tries to have the same effect of switch than the one you can see when calling a phone number : the front view disapear with a zoom effect, while the other one appears also with a zoom effect.
I can't achieve doing that effect, it's always a so-so. There seems to have a scale effect, with an action on opacity, but...
Do you know how this can be done to reflect that effect (not a so-so, I have tons of those) ?
// Make this interesting.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(startupAnimationDone:finished:context:)];
self.view.alpha = 0.0;
self.view.frame = CGRectMake(self.view.center.x,self.view.center.y , 0, 0);
[UIView commitAnimations];
}
I hope this is a framework for a better animation. It's not guaranteed to work, but it's the best I could think of for the first part of the transition.
This will change the frame of your view controller's view so that it "sucks" itself into the center of the screen, which is a natural black color. Now that I think about it, a CGAffineTransform would have been much easier...
EDIT (For pedantry's sake): Starting with iOS 4, you can now use the newer, and much more syntactically clean, animation blocks and a nice transform:
[UIView animateWithDuration:0.25 delay:0.0 options:0 animations:^{
//animate the toolbars in from the top and bottom
[myTopView setFrame:CGRectMake(0, self.view.frame.size.height - 44, self.view.frame.size.width, 44)];
[myBottomView setFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
//fade to black...
self.view.alpha = 0.0;
//and suck inwards.
self.view.frame = CGRectMake(self.view.center.x,self.view.center.y , 0, 0);
}
completion:^{
//do something to end nicely, or start another animation block.
}];

iPhone change height with animation, not downward sweep

I am using the code:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.3];
[info setFrame:CGRectMake( 0, 96, 320, 384)];
[UIView commitAnimations];
to have an animation of the object "info" to change its heght to 384... Nothing else is changed, but the only way to do that is to change the whole frame, and in the animation, instead of the height growing, the object just snaps to the top of the screen with the proper width and height, and just moves downward into place, instead of staying in place and just simply growing. How can I fix it so it does just grow downward?
EDIT: The info is a UITextView, and the downward sweep only happens when you are not scrolled to the top.
Try this:
//... animation setup
CGRect frame = info.frame;
frame.size.height = 384;
info.frame = frame;
[UIView commitAnimations];
Instead of [info setFrame:CGRectMake( 0, 96, 320, 384)]; try info.frame.size.height = 384

Animate move and scale of image UIButton

I want it to be animated so I'm using [UIView beginAnimations]
I've tried animating using button.imageView.frame (with image set as imageView) but it only animates the position, the image doesn't get scaled down at all.
using hateButton.frame (when image is set as backgroundImage), the backgroundImage gets scaled down but it's not animated.
How do I animate-scale a UIButton image?
You can call layoutIfNeeded between [UIView beginAnimations] and [UIView commintAnimations] or with [UIView animateWithDuration].
[UIView animateWithDuration:0.3f animations:^{
self.myButton.frame = aFrame;
[self.myButton layoutIfNeeded];
}];
I could achieve this using Quartz 2D:
// move anchor point without moving frame
CGRect oldFrame = hateButton.frame;
hateButton.layer.anchorPoint = CGPointMake(0, 1); // bottom left
hateButton.frame = oldFrame;
[UIView beginAnimations:nil context:NULL];
CGAffineTransform newTransform;
newTransform = CGAffineTransformMakeScale(0.8, 0.8);
hateButton.transform = CGAffineTransformTranslate(newTransform, 0, -160);
[UIView commitAnimations];
Make sure you import Quartz2D too:
#import <QuartzCore/QuartzCore.h>