Example
Style 1
放大缩小,弹性效果。
Code
- (void)show {
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
[keyWindow addSubview:self];
_alertV.transform = CGAffineTransformMakeScale(0.75, 0.75);
_alertV.alpha = 0.0;
[UIView animateWithDuration:0.7
delay:0.0
usingSpringWithDamping:0.5
initialSpringVelocity:1.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
_alertV.transform = CGAffineTransformMakeScale(1.0, 1.0);
_alertV.alpha = 1.0;
} completion:nil];
}
- (void)dismiss {
[UIView animateWithDuration:0.3 animations:^{
_alertV.transform = CGAffineTransformMakeScale(0.75, 0.75);
_alertV.alpha = 0.0;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
GIF
Style 2
角度旋转,位置移动。
Code
- (void)show {
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
[keyWindow addSubview:self];
[UIView animateWithDuration:0.35 animations:^{
CGRect newFrame = _alertV.frame;
newFrame.origin.y = (SCREEN_HEIGHT-200)/2.0;
_alertV.frame = newFrame;
_alertV.transform = CGAffineTransformMakeRotation(M_1_PI/1.5);
} completion:^(BOOL finished) {
_alertV.transform = CGAffineTransformMakeRotation(0);
}];
}
- (void)dismiss {
[UIView animateWithDuration:0.35f
delay:0.0
options:UIViewAnimationOptionCurveEaseOut animations:^{
CGRect newFrame = _alertV.frame;
newFrame.origin.y = SCREEN_HEIGHT;
_alertV.frame = newFrame;
_alertV.transform = CGAffineTransformMakeRotation(M_1_PI/1.5);
} completion:^(BOOL finished) {
[super removeFromSuperview];
}];
}