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

后端 未结 4 2038
情歌与酒
情歌与酒 2021-01-14 06:14

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 comm

相关标签:
4条回答
  • 2021-01-14 07:02

    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

    0 讨论(0)
  • 2021-01-14 07:09

    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;
                     }];
    }
    
    0 讨论(0)
  • 2021-01-14 07:13

    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){}];
    
    0 讨论(0)
  • 2021-01-14 07:16

    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.

    0 讨论(0)
提交回复
热议问题