How can I animate zoom in / zoom out on iOS using Objective C?
Solution 1
What I was looking for, considering the examples I gave, was a layer of abstraction that would give me most commonly used animation types.
Such types would enable the developer not only to include common animations like zoom in / zoom out, but also would incorporate optimum animation values (To, From, Timing etc.) so that developer doesn't have to worry about those.
I found one such library here, and I believe there are many more.
Solution 2
Use following code for zoom in and zoom out animation.
For Zoom In:
- (void)popUpZoomIn{
popUpView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
[UIView animateWithDuration:0.5
animations:^{
popUpView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);
} completion:^(BOOL finished) {
}];
}
For Zoom Out:
- (void)popZoomOut{
[UIView animateWithDuration:0.5
animations:^{
popUpView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
} completion:^(BOOL finished) {
popUpView.hidden = TRUE;
}];
}
Solution 3
Animations like that can be done without the need for 3rd party libraries.
Example:
self.frame = CGRectMake(0.0f, 0.0f, 200.0f, 150.0f);
[UIView beginAnimations:@"Zoom" context:NULL];
[UIView setAnimationDuration:0.5];
self.frame = CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f);
[UIView commitAnimations];
Example Using Scale Also
UIButton *results = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 100, 100)];
[results addTarget:self action:@selector(validateUserInputs) forControlEvents:UIControlEventTouchDragInside];
[self.view addSubview:results];
results.alpha = 0.0f;
results.backgroundColor = [UIColor blueColor];
results.transform = CGAffineTransformMakeScale(0.1,0.1);
[UIView beginAnimations:@"fadeInNewView" context:NULL];
[UIView setAnimationDuration:1.0];
results.transform = CGAffineTransformMakeScale(1,1);
results.alpha = 1.0f;
[UIView commitAnimations];
source: http://madebymany.com/blog/simple-animations-on-ios
Solution 4
Applied on xCode 7 and iOS 9
//for zoom in
[UIView animateWithDuration:0.5f animations:^{
self.sendButton.transform = CGAffineTransformMakeScale(1.5, 1.5);
} completion:^(BOOL finished){
}];
// for zoom out
[UIView animateWithDuration:0.5f animations:^{
self.sendButton.transform = CGAffineTransformMakeScale(1, 1);
}completion:^(BOOL finished){}];
Nirav Bhatt
iOS Developer: All apps. Professional Website CV SOreadytohelp
Updated on June 04, 2022Comments
-
Nirav Bhatt almost 2 years
I'm looking to replicate the zoom in / zoom out animations so common in iOS applications (example #1, #2). I am specifically looking for a source that can provide some common library with pre-specified values for ideal sort of animations. Like for zoom in, it should come with preconfigured transform values that are easily identifiable by human eye. Something like pop-animation and so on.
I assume these must be fairly well supported in iOS, either by a library or direct API support... But I'm not sure where to even start.
-
Nirav Bhatt over 11 yearsThanks, I know of this. However this is the simplest kind that I could mention. I am looking for most common types that are visually appealing so that user wouldn't even have to play with values.
-
David Rönnqvist over 11 years@NiravBhatt What common types are you looking for? The more information you put in the question the better we can help you? What do you mean with the "user" playing with the values? Are you the user of the API or is it the actual end-user that should be able to customize their animations within the app?
-
Nirav Bhatt over 11 yearsIf I am end user I should not have to play with values - that's what I meant by mostly commonly used animations.
-
Nirav Bhatt about 11 years@DavidRönnqvist - please see my comment above, I was looking for library for developers as end users.
-
Nirav Bhatt over 9 yearsPlease read the comments and other answers. This is NOT what I am looking for.