Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save painteddigital/b5f6041edfe6209036b1 to your computer and use it in GitHub Desktop.
Save painteddigital/b5f6041edfe6209036b1 to your computer and use it in GitHub Desktop.
Adds image from library to a parent view and animates it by growing from the center with a springy bounce
- (void)addCompletionCheck {
// image asset. Change to whatever your's is named
UIImage *check = [UIImage imageNamed:@"uploadCompleteCheck"];
UIImageView *checkImageView = [[UIImageView alloc] initWithImage:check];
// create a view to house the check and for animating
UIView *checkView = [UIView new];
// Calculate position based on parent and initial size of asset
// Math is such that it puts the image in the center of parent
// self.progressView is the parent view in this case. Change to your superview
int x = self.progressView.frame.size.width/2 - checkImageView.frame.size.width/2;
int y = self.progressView.frame.size.height/2 - checkImageView.frame.size.height/2;
int defaultWidth = checkImageView.frame.size.width;
int defaultHeight = checkImageView.frame.size.height;
// add the imageview to the superview
[checkView addSubview:checkImageView];
[self.progressView addSubview:checkView];
// position subview and its subview
checkView.frame = CGRectMake(x,y,defaultWidth,defaultHeight);
checkImageView.frame = CGRectMake(0,0,defaultWidth,defaultHeight);
// Make original scale 0%
CGAffineTransform currentTransform = checkView.transform;
CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, 0, 0);
[checkView setTransform:newTransform];
// Animate to new scale of 100% with bounce
[UIView animateWithDuration:0.3
delay:0
usingSpringWithDamping:0.6
initialSpringVelocity:15
options:0
animations:^{
checkView.transform = CGAffineTransformMakeScale(1, 1);
}
completion:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment