zoukankan      html  css  js  c++  java
  • 提示信息View自动收回

    #import <UIKit/UIKit.h>
    
    @interface NotifyView : UIView
    /*  param 1 父view  param2  将要用来提示的内容  */
    +(void)showNotifyInSuperView:(UIView *)superView context:(NSString *)aString;
    
    @end
    //
    //  NotifyView.m
    //  NotifyViewText
    //
    //  Created by admin on 16/1/15.
    //  Copyright © 2016年 123. All rights reserved.
    //
    
    #import "NotifyView.h"
    
    @implementation NotifyView
    +(void)showNotifyInSuperView:(UIView *)superView context:(NSString *)aString
    {
        NotifyView *ntfv = (NotifyView *)[superView viewWithTag:12345];
        if (!ntfv)
        {
            ntfv = [[NotifyView alloc]initWithFrame:CGRectMake(0, 0, 280, 120)];
            ntfv.center = superView.center;
            ntfv.tag = 12345;
            ntfv.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
            ntfv.layer.cornerRadius = 12.0f;
            ntfv.clipsToBounds = YES;
            ntfv.layer.masksToBounds = YES;
            [superView addSubview:ntfv];
            
            UILabel *label  = [UILabel new];
            label.frame = CGRectMake(8, 8, ntfv.bounds.size.width - 16, ntfv.bounds.size.height - 16);
            label.text = aString;
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor whiteColor];
            label.numberOfLines = 3;
            label.lineBreakMode = NSLineBreakByWordWrapping;
            label.backgroundColor = [UIColor clearColor];
            [ntfv addSubview:label];
    
        }else
        {
           ntfv.alpha = 0.9;
        }
        [UIView animateWithDuration:1.0 animations:^{
            [ntfv.superview bringSubviewToFront:ntfv];
        }];
        [NSTimer scheduledTimerWithTimeInterval:2.0f target:ntfv selector:@selector(timerFired:) userInfo:@{@"view":ntfv} repeats:NO];
    }
    -(void)timerFired:(NSTimer *)sender
    {
        NotifyView *ntfv = sender.userInfo[@"view"];
        [UIView animateWithDuration:1.0 animations:^{
            [ntfv.superview sendSubviewToBack:ntfv];
            ntfv.alpha = 0.0;
            [sender invalidate];
        }];
    }
    @end

    调用方式

    1.导入头文件

    #import "NotifyView.h"

    2.通过类提供的接口调用----(输入需要展示的参数内容!!!)

    - (IBAction)showNotify:(UIButton *)sender
    {
        [NotifyView showNotifyInSuperView:self.view context:@"微卡京东方货架上的高房价华盛顿号开发商的积分卡水电费水电费更好的房价考核和哪个部分"];
    }
  • 相关阅读:
    Linux日志文件/var/log详解
    QT 的信号与槽机制介绍
    利用线程通信,写2个线程,一个线程打印1~52,另一个线程打印A~Z,打印顺序应该使12A34B56C···5152Z
    mysql快速安装
    zabbix安装源
    mysql手动安装
    没有可用软件包 zabbixservermysql
    【转载】web 部署专题(一):Gunicorn运行与配置方法
    supervisor快速配置
    linux监控脚本状态失败后拉起
  • 原文地址:https://www.cnblogs.com/Mgs1991/p/5138894.html
Copyright © 2011-2022 走看看