|
@@ -37,155 +37,6 @@
|
|
|
return YES;
|
|
|
}
|
|
|
|
|
|
-+ (void)showToastWithTitle:(NSString *)titleStr onComplete:(void(^)())onComplete
|
|
|
-{
|
|
|
- UIView *toastView = [[UIView alloc] initWithFrame:kFrame(0, 0, 260.f, 21.f)];
|
|
|
- UILabel *titleLabel = [[UILabel alloc] initWithFrame:kFrame(0, 0, 200, 21.f)];
|
|
|
-
|
|
|
- UIView *bgView = [[UIView alloc] initWithFrame:toastView.bounds];
|
|
|
- [bgView setBackgroundColor:kCOLOR(blackColor)];
|
|
|
- [bgView setAlpha:0.4];
|
|
|
- [toastView addSubview:bgView];
|
|
|
-
|
|
|
- [titleLabel setBackgroundColor:kCOLOR(clearColor)];
|
|
|
- [titleLabel setTextColor:kCOLOR(whiteColor)];
|
|
|
- [titleLabel setFont:kFONT(13.f)];
|
|
|
- [titleLabel setText:titleStr];
|
|
|
- [titleLabel setTextAlignment:NSTextAlignmentCenter];
|
|
|
- [titleLabel setCenter:toastView.center];
|
|
|
- [toastView addSubview:titleLabel];
|
|
|
-
|
|
|
- [toastView setBackgroundColor:kCOLOR(clearColor)];
|
|
|
- [toastView.layer setMasksToBounds:YES];
|
|
|
- [toastView.layer setCornerRadius:3];
|
|
|
- [toastView setCenter:kPoint(160.f, -20)];
|
|
|
- [[AppDelegate appDelegate].window addSubview:toastView];
|
|
|
-
|
|
|
- [UIView animateWithDuration:0.5 animations:^{
|
|
|
- [toastView setBottom:58];
|
|
|
- } completion:^(BOOL finished) {
|
|
|
- double delayInSeconds = 1.0;
|
|
|
- dispatch_time_t delayInNanoSeconds =dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
|
|
|
- dispatch_queue_t concurrentQueue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
|
|
- dispatch_after(delayInNanoSeconds, concurrentQueue, ^(void){
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- [UIView animateWithDuration:0.35 animations:^{
|
|
|
- [toastView setTop:-20];
|
|
|
- } completion:^(BOOL finished) {
|
|
|
- [toastView removeFromSuperview];
|
|
|
- onComplete();
|
|
|
- }];
|
|
|
- });
|
|
|
- });
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
-static NSString* toastTitleStr = @"";
|
|
|
-+ (void)showToastWithTitle:(NSString *)titleStr
|
|
|
-{
|
|
|
- //如果相同,则不显示
|
|
|
- if ([toastTitleStr isEqualToString:titleStr])
|
|
|
- return;
|
|
|
-
|
|
|
- toastTitleStr = titleStr;
|
|
|
-
|
|
|
- CGRect rect = [UIScreen mainScreen].bounds;
|
|
|
- CGFloat winWidth = rect.size.width;
|
|
|
-
|
|
|
- UIView *toastView = [[UIView alloc] initWithFrame:kFrame(0, 0, winWidth-30, 21.f)];
|
|
|
- UILabel *titleLabel = [[UILabel alloc] initWithFrame:kFrame(0, 0, winWidth-30*2, 21.f)];
|
|
|
-
|
|
|
- UIView *bgView = [[UIView alloc] initWithFrame:toastView.bounds];
|
|
|
- [bgView setBackgroundColor:kCOLOR(blackColor)];
|
|
|
- [bgView setAlpha:0.4];
|
|
|
- [toastView addSubview:bgView];
|
|
|
-
|
|
|
- [titleLabel setBackgroundColor:kCOLOR(clearColor)];
|
|
|
- [titleLabel setTextColor:kCOLOR(whiteColor)];
|
|
|
- [titleLabel setFont:kFONT(13.f)];
|
|
|
- [titleLabel setText:titleStr];
|
|
|
- [titleLabel setTextAlignment:NSTextAlignmentCenter];
|
|
|
- [titleLabel setCenter:toastView.center];
|
|
|
- [toastView addSubview:titleLabel];
|
|
|
-
|
|
|
- [toastView setBackgroundColor:kCOLOR(clearColor)];
|
|
|
- [toastView.layer setMasksToBounds:YES];
|
|
|
- [toastView.layer setCornerRadius:3];
|
|
|
- [toastView setCenter:kPoint([AppDelegate appDelegate].window.center.x, -20)];
|
|
|
- [[AppDelegate appDelegate].window addSubview:toastView];
|
|
|
-
|
|
|
- [UIView animateWithDuration:0.5 animations:^{
|
|
|
- [toastView setBottom:58];
|
|
|
- } completion:^(BOOL finished) {
|
|
|
- double delayInSeconds = 1.0;
|
|
|
- dispatch_time_t delayInNanoSeconds =dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
|
|
|
- dispatch_queue_t concurrentQueue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
|
|
- dispatch_after(delayInNanoSeconds, concurrentQueue, ^(void){
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- [UIView animateWithDuration:0.35 animations:^{
|
|
|
- [toastView setTop:-20];
|
|
|
- } completion:^(BOOL finished) {
|
|
|
- [toastView removeFromSuperview];
|
|
|
- toastTitleStr = @"";
|
|
|
- }];
|
|
|
- });
|
|
|
- });
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
-+ (void)showLongToastWithTitle:(NSString *)titleStr
|
|
|
-{
|
|
|
- //如果相同,则不显示
|
|
|
- if ([toastTitleStr isEqualToString:titleStr])
|
|
|
- return;
|
|
|
-
|
|
|
- toastTitleStr = titleStr;
|
|
|
-
|
|
|
- CGRect rect = [UIScreen mainScreen].bounds;
|
|
|
- CGFloat winWidth = rect.size.width;
|
|
|
-
|
|
|
- UIView *toastView = [[UIView alloc] initWithFrame:kFrame(0, 0, winWidth-30, 21.f)];
|
|
|
- UILabel *titleLabel = [[UILabel alloc] initWithFrame:kFrame(0, 0, winWidth-30*2, 21.f)];
|
|
|
-
|
|
|
- UIView *bgView = [[UIView alloc] initWithFrame:toastView.bounds];
|
|
|
- [bgView setBackgroundColor:kCOLOR(blackColor)];
|
|
|
- [bgView setAlpha:0.4];
|
|
|
- [toastView addSubview:bgView];
|
|
|
-
|
|
|
- [titleLabel setBackgroundColor:kCOLOR(clearColor)];
|
|
|
- [titleLabel setTextColor:kCOLOR(whiteColor)];
|
|
|
- [titleLabel setFont:kFONT(13.f)];
|
|
|
- titleLabel.adjustsFontSizeToFitWidth = YES;
|
|
|
- [titleLabel setText:titleStr];
|
|
|
- [titleLabel setTextAlignment:NSTextAlignmentCenter];
|
|
|
- [titleLabel setCenter:toastView.center];
|
|
|
- [toastView addSubview:titleLabel];
|
|
|
-
|
|
|
- [toastView setBackgroundColor:kCOLOR(clearColor)];
|
|
|
- [toastView.layer setMasksToBounds:YES];
|
|
|
- [toastView.layer setCornerRadius:3];
|
|
|
- [toastView setCenter:kPoint([AppDelegate appDelegate].window.center.x, -20)];
|
|
|
- [[AppDelegate appDelegate].window addSubview:toastView];
|
|
|
-
|
|
|
- [UIView animateWithDuration:0.5 animations:^{
|
|
|
- [toastView setBottom:58];
|
|
|
- } completion:^(BOOL finished) {
|
|
|
- double delayInSeconds = 3.0;
|
|
|
- dispatch_time_t delayInNanoSeconds =dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
|
|
|
- dispatch_queue_t concurrentQueue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
|
|
- dispatch_after(delayInNanoSeconds, concurrentQueue, ^(void){
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- [UIView animateWithDuration:0.35 animations:^{
|
|
|
- [toastView setTop:-20];
|
|
|
- } completion:^(BOOL finished) {
|
|
|
- [toastView removeFromSuperview];
|
|
|
- toastTitleStr = @"";
|
|
|
- }];
|
|
|
- });
|
|
|
- });
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
+ (void)postInformation:(NSString *)name
|
|
|
{
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:name object:nil];
|