Last active
December 6, 2016 04:15
-
-
Save hk0i/7ff6125f5ce4adea33540189c6650113 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Promise style method | |
*/ | |
- (void)animateUi | |
{ | |
const CGFloat valDestStatsBottom = self.conStatsBottomSpacing.constant; | |
const CGFloat valDestLeftArrowTrailing = self.conLeftArrowTrailing.constant; | |
const CGFloat valDestRightArrowLeading = self.conRightArrowLeading.constant; | |
const CGFloat valDestBtnRollTheDiceHeight = self.conBtnRollTheDiceHeight.constant; | |
//TODO: clean this up by separating the methods and pulling out | |
//constraints from the storyboard before resetting to 0. | |
{ | |
//set initial states | |
//move arrows before animating | |
self.conLeftArrowTrailing.constant = 0; | |
self.conRightArrowLeading.constant = 0; | |
self.conBtnRollTheDiceHeight.constant = 0; | |
self.conStatsBottomSpacing.constant += 20; | |
//apply constraints | |
[self.view layoutIfNeeded]; | |
//set alphas | |
self.imgChampionPortrait.alpha = 0; | |
self.portraitBorderView.alpha = 0; | |
self.btnRightArrow.alpha = 0; | |
self.btnLeftArrow.alpha = 0; | |
self.btnRollTheDice.alpha = 0; | |
self.uivStatsContainer.alpha = 0; | |
self.lblDescription.alpha = 0; | |
} | |
[UIView promiseWithDuration:.5f delay:.3f options:UIViewAnimationOptionCurveEaseIn animations:^{ | |
self.imgChampionPortrait.alpha = 1; | |
self.portraitBorderView.alpha = .5; | |
}].then(^{ | |
//wait to start the arrow movement | |
return PMKAfter(.25f); | |
}).thenOn(dispatch_get_main_queue(), ^{ | |
//set up final arrow constraints | |
self.conLeftArrowTrailing.constant = valDestLeftArrowTrailing; | |
self.conRightArrowLeading.constant = valDestRightArrowLeading; | |
//animate the arrow opacity and constraints | |
return [UIView promiseWithDuration:.25f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{ | |
[self.view layoutIfNeeded]; | |
self.btnRightArrow.alpha = .35; | |
self.btnLeftArrow.alpha = .35; | |
}]; | |
}).then(^{ | |
//animate rtd button | |
self.conBtnRollTheDiceHeight.constant = valDestBtnRollTheDiceHeight; | |
return [UIView promiseWithDuration:.5f delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{ | |
[self.view layoutIfNeeded]; | |
self.btnRollTheDice.alpha = 1; | |
}]; | |
}).then(^{ | |
//start button glow | |
[self.btnRollTheDice startGlowing]; | |
//move stats in from bottom | |
self.conStatsBottomSpacing.constant = valDestStatsBottom; | |
return [UIView promiseWithDuration:.5f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{ | |
[self.view layoutIfNeeded]; | |
self.uivStatsContainer.alpha = 1; | |
self.lblDescription.alpha = 1; | |
}]; | |
}); | |
} | |
/** | |
* Original Callback Nested Style | |
*/ | |
- (void)oldAnimationMethod { | |
const CGFloat valDestStatsBottom = self.conStatsBottomSpacing.constant; | |
const CGFloat valDestLeftArrowTrailing = self.conLeftArrowTrailing.constant; | |
const CGFloat valDestRightArrowLeading = self.conRightArrowLeading.constant; | |
const CGFloat valDestBtnRollTheDiceHeight = self.conBtnRollTheDiceHeight.constant; | |
[UIView animateWithDuration:.5f delay:.3f options:UIViewAnimationOptionCurveEaseIn animations:^{ | |
self.imgChampionPortrait.alpha = 1; | |
self.portraitBorderView.alpha = .5; | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
//set up final arrow constraints | |
self.conLeftArrowTrailing.constant = valDestLeftArrowTrailing; | |
self.conRightArrowLeading.constant = valDestRightArrowLeading; | |
//start animating arrows | |
[UIView animateWithDuration:.25f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{ | |
[self.view layoutIfNeeded]; | |
self.btnRightArrow.alpha = .35; | |
self.btnLeftArrow.alpha = .35; | |
} completion:^(BOOL isFinished) { | |
//animate rtd button | |
self.conBtnRollTheDiceHeight.constant = valDestBtnRollTheDiceHeight; | |
[UIView animateWithDuration:.5f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{ | |
[self.view layoutIfNeeded]; | |
self.btnRollTheDice.alpha = 1; | |
} completion:^(BOOL isFinished) { | |
[self.btnRollTheDice startGlowing]; | |
self.conStatsBottomSpacing.constant = valDestStatsBottom; | |
[UIView animateWithDuration:.5f delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{ | |
[self.view layoutIfNeeded]; | |
self.uivStatsContainer.alpha = 1; | |
self.lblDescription.alpha = 1; | |
} completion:^(BOOL isFinished) { | |
}]; | |
}]; | |
}]; | |
}); | |
} completion: nil]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment