Nirav Bhatt
Nirav Bhatt

Reputation: 6969

How can I animate zoom in / zoom out on iOS using Objective C?

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.

Upvotes: 3

Views: 17784

Answers (4)

Ahmed Abdallah
Ahmed Abdallah

Reputation: 2355

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){}];

Upvotes: 2

Piyush
Piyush

Reputation: 1224

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;
                 }];
}

Upvotes: 18

Nirav Bhatt
Nirav Bhatt

Reputation: 6969

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.

Upvotes: 1

propstm
propstm

Reputation: 3629

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

Upvotes: 11

Related Questions