How can I use this downloaded Class(es) on my Prototype Routine?

Posted by O.C. on Stack Overflow See other posts from Stack Overflow or by O.C.
Published on 2010-04-04T07:37:36Z Indexed on 2010/04/04 7:43 UTC
Read the original article Hit count: 373

I'm a newbie and I'm in need of some help. I'm working on a prototype for an app, but I'm learning at the same time.

I want to display a popup image over a given UIView, but I would like it to behave like the UIAlertView or like the Facebook Connect for iPhone modal popup window, in that it has a bouncy, rubbber-band-like animation to it.

I was able to find the following class(es) on the net, from someone who was trying to do something similar. He/she put this together, but there was no Demo, no instructions nor a way to contact them.

Being that I am so new, I don't have any idea as to how to incorporate this into my code.

This is the routine where I need the bouncy image to appear...

//========================================================
//
//  productDetail
//

- (void) showProductDetail
{
    _productDetailIndex++;
    if (_productDetailIndex > 7) { return; }

    else if (_productDetailIndex == 1) {
        NSString* filename = [NSString stringWithFormat:@"images/ICS_CatalogApp_0%d_ProductDetailPopup.png", _productDetailIndex];
        [_productDetail setImageWithName:filename];

        _productDetail.transform = CGAffineTransformMakeScale(0.1,0.1);
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.5];
        // other animations goes here
        _productDetail.transform = CGAffineTransformMakeScale(1,1);
        // other animations goes here
        [UIView commitAnimations];
    }

    NSString* filename = [NSString stringWithFormat:@"images/ICS_CatalogApp_0%d_ProductDetailPopup.png", _productDetailIndex];
    [_productDetail setImageWithName:filename];

    _productDetail.x = (self.width - _productDetail.width);
    _productDetail.y = (self.height - _productDetail.height);
}

and here is the code I found...

float pulsesteps[3] = { 0.2, 1/15., 1/7.5 };
- (void) pulse {
    self.transform = CGAffineTransformMakeScale(0.6, 0.6);
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:pulsesteps[0]];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(pulseGrowAnimationDidStop:finished:context:)];
    self.transform = CGAffineTransformMakeScale(1.1, 1.1);
    [UIView commitAnimations];
}

- (void)pulseGrowAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {   
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:pulsesteps[1]];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(pulseShrinkAnimationDidStop:finished:context:)];
    self.transform = CGAffineTransformMakeScale(0.9, 0.9);
    [UIView commitAnimations];
}

- (void)pulseShrinkAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:pulsesteps[2]];
    self.transform = CGAffineTransformIdentity;
    [UIView commitAnimations];
}

My routine is based on the Prototyping class given by Apple during WWDC 09. It may not be "correct" but it works as is. I just would like to add the animation to this image/screen to really make the concept clear.

© Stack Overflow or respective owner

Related posts about cocoa-touch

Related posts about iphone-sdk-3.0