Open chenminghong opened 6 years ago
HUToast弹出框的类里面有很多个错误需要更正。 1.单例类里面没有调用initWithFrame:,导致toast没有指定frame; 2.msgLab属性声明的是assign类型,会被释放,导致后面该变量始终未nil,无法复制width和msg; 3.所有的UIViewAnimation动画类方法的completion:^(BOOL finished) { } Block块中的代码未添加finish判断,导致提示框view出现后就隐藏,因为该代码块在动画执行的时候会始终不停的调用,只有当finishe为YES的时候执行代码块才是正确的操作; 4.最后虽然还有诸多问题,但是还是非常感谢作者的贡献,很好用的框架,给个大大的攒!以下是本人修改的代码,由于时间紧急,临时修改,可能以下代码存在诸多问题,但是还是希望作者能及时更正并采纳。
(instancetype)toast { static HUToast *toast = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ toast = [[self alloc] initWithFrame:CGRectMake((kScreenWidth-80)/2, (kScreenHeight-50)/2, 100, 30)]; toast.msgLab = [[UILabel alloc] initWithFrame:toast.bounds]; toast.msgLab.textColor = [UIColor whiteColor]; toast.msgLab.font = [UIFont systemFontOfSize:13]; toast.msgLab.numberOfLines = 0; toast.msgLab.textAlignment = NSTextAlignmentCenter; [toast addSubview:toast.msgLab]; toast.didHiden = YES; }); return toast; }
(void)showToastWithMsg:(NSString *)msg { [[HUToast toast] showToastWithMsg:msg]; }
(instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.layer.cornerRadius = 6; self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8]; self.alpha = 0; } return self; }
(void)showToastWithMsg:(NSString *)msg { if (!self.didHiden) { return; }
CGFloat width = [msg sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]}].width+16; self.width = width; self.msgLab.width = width; self.msgLab.text = msg; [self showToast]; }
(void)showToast { self.didHiden = NO; UIWindow *window = [UIApplication sharedApplication].keyWindow; [window addSubview:[HUToast toast]]; [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ self.alpha = 1; } completion:^(BOOL finished) { if (finished) { [NSTimer scheduledTimerWithTimeInterval:kDefaultDuration target:self selector:@selector(hideToash:) userInfo:nil repeats:NO]; } }]; }
(void)hideToash:(NSTimer *)timer { [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ self.alpha = 0; } completion:^(BOOL finished) { if (finished) { [self removeFromSuperview]; self.didHiden = YES; [timer invalidate]; } }]; }
就是我点击保存按钮之后,没有显示保存结果的提示文字,就是类似网易新闻那种,保存成功之后应该提示保存成功的,我看了源码,里面有这样的功能,但是我这边点击保存是看不到提示文字的效果的。。。请问怎么解决?还有就是保存按钮建议换成网易新闻的那种下载图片按钮,比文字好看,建议更改为下载图片比较好!