Reputation: 5597
I have an UIImageView
object with the frame, say, x = 0, y = 100, width = 320, height = 200.
Now I want to make an animation such that this image can be shown gradually, meaning that the height of the showing part is growing from 0 to 200 gradually.
I tried to realize this by resizing the image frame, but if I do so, the image itself will be scaled accordingly, which is not what I want.
I also tried to set "Mode" of the UIImageView
to "Top" rather than "Scale to Fit". But because I'm doing this in the XCode inspector, the image loaded is, for example, [email protected]
, so if I choose "Top", the image will be 2 times bigger.
By the way, I also have tried to use a covering rectangle and move it. But this method will together cover other background images, so does not work.
Could anyone help?
Upvotes: 1
Views: 284
Reputation: 1827
You can add it like this:
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,0)];
view.clipsToBounds = YES;
UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake:(0,0,320,200)];
imgView.contentMode = UIViewContentModeScaleAspectFit;
imgView.image = [UIImage imageNamed:@"your image"];
[view addSubview:imgView];
[imgView release];
[self.view addSubview:view];
Now you do this:
[UIView beginAnimations:@"" context:nil];
[UIView setAnimationDuration:1.5];
[view setFrame:CGRectMake(0,0,320,200)];
[UIView commitAnimations];
This is tested!
Upvotes: 0
Reputation: 5268
can use something like this
image.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:5.0 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
// animate it to the identity transform (100% scale)
image.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
// if you want to do something once the animation finishes, put it here
}];
Upvotes: 0
Reputation: 47049
First give height of your Imageview
is 0.
And Take a NSTimer
(here with method name doAnimation
) and give its TimeInterVal
is 1 Second.
Here doAnimation
method fire after 1 second. Write code of doAnimation
method.
-(void)doAnimation
{
//// here you can give animation duration as you want.
[UIView animateWithDuration:0.35 animations:^{
self.myImageView.frame=CGRectMake(0, 100, 320,200);
}];
}
This code might help you in your case:
Upvotes: 0
Reputation: 7484
You can use the mask property of CALayer that backs the imageView (e.g. imgView.layer.mask
). You should be able to animate that.
Upvotes: 1