12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- //
- // HFAlert.m
- // smartRhino
- //
- // Created by niuzhen on 2020/4/30.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "HFAlert.h"
- static UINib *ViewNib = nil;
- @interface HFAlert()
- @end
- static HFAlert *alert = nil;
- static dispatch_once_t onceToken;
- @implementation HFAlert
- + (instancetype)share
- {
- dispatch_once(&onceToken, ^{
- if (ViewNib == nil) {
- ViewNib = [UINib nibWithNibName:@"HFAlert" bundle:nil];
- }
- alert = [[ViewNib instantiateWithOwner:nil options:nil] lastObject];
- alert.titleL.layer.cornerRadius = 4.f;
- alert.titleL.layer.masksToBounds = YES;
- [alert setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- alert.backgroundColor = [UIColor clearColor];
- // [alert.disBtn addTarget:alert action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
- });
- return alert;
- }
- - (void)showText:(NSString *)text
- {
- WS(weakSelf);
- self.titleL.text = text;
- UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
- [window addSubview:self];
- [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
- } completion:^(BOOL finished) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [weakSelf dismiss];
- });
- }];
- }
- - (void)dismiss
- {
- WS(weakSelf);
- [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
- } completion:^(BOOL finished) {
- [weakSelf removeFromSuperview];
- }];
- }
- @end
|