showHint弹屏显示

-(void)showHint:(NSString *)connent andTime:(float)aTime andHeight:(float)height{
    NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:15]};
    CGSize size = [connent boundingRectWithSize:CGSizeMake(200, 60) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
    
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake((ScreenWidth-size.width-5)/2, height, size.width+10, size.height+30)];
    view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.8];
    view.layer.cornerRadius = 5;
    view.layer.masksToBounds = YES;
    [self.view addSubview:view];
    
    UILabel * label = [[UILabel alloc]initWithFrame:view.bounds];
    label.backgroundColor = [UIColor clearColor];
    label.text = connent;
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:15];
    label.textAlignment = NSTextAlignmentCenter;
    label.numberOfLines = 2;
    [view addSubview:label];
    
    [UIView animateWithDuration:0.3 animations:^{
        view.frame = CGRectMake((ScreenWidth-size.width-5)/2, height, size.width+10, size.height+30);
    } completion:^(BOOL finished) {
        if (self) {
            [self performSelector:@selector(hideHintView:) withObject:view afterDelay:aTime];
        }
    }];
}
//显示
-(void)showTopReminder:(NSString *)content withDuration:(NSTimeInterval)duration withExigency:(BOOL)exigency isSucceed:(BOOL)succeed{
    UIView * subView = [self.view viewWithTag:8950];
    if (subView) {
        return;
    }else{
        NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:12]};
        CGSize size = [content boundingRectWithSize:CGSizeMake(SCREEN_W-20, 200) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
        UIView * view  = [[UIView alloc] init];
            view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.85];
        
        view.tag = 8950;
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectZero];
        label.font = [UIFont systemFontOfSize:14];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = content;
        label.numberOfLines = 0;
        [view addSubview:label];
        
        UIImageView * imageView = [[UIImageView alloc]init];
        if (succeed) {
            imageView.image = [UIImage imageNamed:@"icon_success_hite"];
        }else{
            imageView.image = [UIImage imageNamed:@"icon_dialog"];
        }
        
        
        if(exigency){
            view.frame = CGRectMake(0, -size.height-20/2, SCREEN_W, size.height+20);
            view.layer.cornerRadius = 0;
            view.layer.masksToBounds = YES;
            view.backgroundColor = [UIColor colorWithHex:0xe73c3c alpha:0.85];
            
            label.textColor = [UIColor whiteColor];
            label.frame = CGRectMake(10, 10, SCREEN_W-20, size.height);
        }else{
            view.frame = CGRectMake((CGRectGetWidth(self.view.frame)-230/2)/2, (CGRectGetHeight(self.view.frame)-230/2)/2, 230/2, 230/2);
            view.layer.cornerRadius = 8;
            view.layer.masksToBounds = YES;
            imageView.frame = CGRectMake((CGRectGetWidth(view.frame)-69/2)/2, (CGRectGetHeight(view.frame)-69/2)/2-16, 69/2, 69/2);
            [view addSubview:imageView];
            label.frame = CGRectMake(0, CGRectGetMaxY(imageView.frame)+10, CGRectGetWidth(view.frame), 45);
            label.textColor = [UIColor colorWithHex:0xffffff alpha:0.9];
            label.font = [UIFont systemFontOfSize:14];
        }
        
        [self.view addSubview:view];
        
        
        
        [UIView animateWithDuration:0.25 animations:^{
            if (exigency) {
                if(self.navigationController==nil){
                    view.frame = CGRectMake(0, 20, SCREEN_W, size.height+20);
                }else{
                    view.frame = CGRectMake(0, 64, SCREEN_W, size.height+20);
                }
            }else{
            }
        } completion:^(BOOL finished) {
            if (self) {
                [self performSelector:@selector(hideTopView:) withObject:view afterDelay:/*duration*/1];
            }
        }];
    }
}
//隐藏
-(void)hideTopView:(UIView *)aView
{
    [UIView animateWithDuration:0.1 animations:^{
        if (aView.frame.size.width>130) {
            aView.center = CGPointMake(SCREEN_W/2, -200);
        }else{
            aView.backgroundColor = [UIColor colorWithHex:0x000000 alpha:0.0];
            aView.alpha = 0;
        }
        
        
    } completion:^(BOOL finished) {
        [aView removeFromSuperview];
    }];
}

你可能感兴趣的:(showHint弹屏显示)