美文网首页工具
AlertView 弹出动画

AlertView 弹出动画

作者: 秋月夜 | 来源:发表于2016-03-07 16:41 被阅读169次

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

YYAlertView0.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];
    }];
}

GIF

YYAlertView1.gif

GitHub

相关文章

网友评论

    本文标题:AlertView 弹出动画

    本文链接:https://www.haomeiwen.com/subject/ytnakttx.html