笔记篇IOS知识梳理

动画弹出收起

2022-08-18  本文已影响0人  失忆的程序员

// MARK: ----- 动画弹出
- (void)showWithCompletion:(void (^)(void))completion {
    self.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.0];
    [UIView animateWithDuration:0.25f animations:^{
        CGRect frame = self.frame;
        frame.origin.y = self.frame.size.height - frame.size.height;
        self.frame = frame;
    } completion:^(BOOL finished) {
        !completion ? : completion();
    }];
}
// MARK: ----- 动画收起
- (void)dismiss:(void (^)(void))completion {
    self.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.0];
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES]; /// 收起键盘
    [UIView animateWithDuration:0.25f animations:^{
        CGRect frame = self.frame;
        frame.origin.y = self.frame.size.height;
        self.frame = frame;
    }completion:^(BOOL finished) {
        !completion ? : completion();
        [self removeFromSuperview];
    }];
}

上一篇 下一篇

猜你喜欢

热点阅读