Last active
December 21, 2015 22:19
-
-
Save tony0x59/6374705 to your computer and use it in GitHub Desktop.
从顶部弹出视图的动画效果,当退出视图时调用[self leaveView]将视图弹出。
This file contains 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
#pragma mark - UIAnimation | |
- (void)willMoveToSuperview:(UIView *)newSuperview | |
{ | |
[self enterView]; | |
} | |
#define ANIMATE_DURATION 0.3 | |
- (void)enterView | |
{ | |
self.backgroundColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.0]; | |
CATransition *transition = [CATransition animation]; | |
transition.duration = ANIMATE_DURATION; | |
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | |
transition.type = kCATransitionMoveIn; | |
transition.subtype = kCATransitionFromBottom; | |
[_mainView.layer addAnimation:transition forKey:nil]; | |
[UIView animateWithDuration:ANIMATE_DURATION animations:^{ | |
self.backgroundColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.85]; | |
}]; | |
} | |
- (void)leaveView | |
{ | |
CATransition *transition = [CATransition animation]; | |
transition.duration = ANIMATE_DURATION; | |
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | |
transition.type = kCATransitionReveal; | |
transition.subtype = kCATransitionFromTop; | |
transition.delegate = self; | |
[_mainView.layer addAnimation:transition forKey:nil]; | |
} | |
- (void)animationDidStart:(CAAnimation *)anim | |
{ | |
_mainView.alpha = 0.0; | |
[UIView animateWithDuration:ANIMATE_DURATION animations:^{ | |
self.alpha = 0.0; | |
}]; | |
} | |
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag | |
{ | |
[self removeFromSuperview]; | |
} | |
#pragma mark - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment