CGRect endFrame1 = [_inputFields[0] frame];
CGRect endFrame2 = [_inputFields[1] frame];
CGRect startFrame1 = endFrame1;
CGRect startFrame2 = endFrame2;
startFrame1.origin.y -= 100;
startFrame2.origin.y -= 50;
CGRect *start = calloc(2, sizeof(CGRect));
start[0] = startFrame1;
start[1] = startFrame2;
CGRect *end = calloc(2, sizeof(CGRect));
end[0] = endFrame1;
end[1] = endFrame2;
[_inputFields enumerateObjectsUsingBlock:^(UITextField *obj, NSUInteger idx, BOOL *stop) {
[obj setFrame:start[idx]];
[obj setAlpha:0.0];
}];
[UIView animateWithDuration:0.6 delay:0.0 usingSpringWithDamping:1.0 initialSpringVelocity:0.5 options:UIViewAnimationOptionCurveEaseIn animations:^{
[_inputFields enumerateObjectsUsingBlock:^(UITextField *obj, NSUInteger idx, BOOL *stop) {
[obj setFrame:end[idx]];
[obj setAlpha:1.0];
}];
} completion:^(BOOL finished) {
free(start);
free(end);
}];
I am a second year Software Engineering student at the Rochester Institute of Technology and here is my story.
Saturday, June 29, 2013
A perfectly valid way to animate some views.
For an app I'm developing I wanted to have two UITextFields animate on screen. There are a thousand different ways to do this. I ended up using and IBOutletCollection containing my two views and some fast enumeration blocks (no different then a for in loop other then indexes and a boolean stop pointer). You can take a look at my code here. I had to allocate an array for my CGRects because I can only access a reference inside the blocks, so by putting them into an array I was able to grab the pointer that was allocated. Then in my completion block I freed the arrays, if I did this outside the UIView animation block, I would have lost my arrays before the animation completed and I would inevitably end up seg faulting. This was just another different way at looking at a problem that I wanted to share.
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment