当前位置: 首页 > news >正文

简单弹出视图

#import "loveView.h"
//点击按钮
-(void)buttonclick
{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
loveView *loveview = [[loveView alloc] initWithFrame:window.bounds];
loveview.alpha = 0;
[window.rootViewController.view addSubview:loveview];
[UIView animateWithDuration:0.5
                 animations:^{
        loveview.alpha = 1.0;
    }
 ];
}

  

#import "loveView.h"

@implementation loveView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        [self   creatView];
        
    }
    return self;
}

-(void)creatView
{

    [self setBackgroundColor:[UIColor clearColor]];
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
    backView.center = self.center;
    [backView setBackgroundColor:[UIColor blackColor]];
    [self addSubview:backView];
    backView.alpha = 0.3;
    
    UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 200)];
    mainView.center = self.center;
    [mainView setBackgroundColor:[UIColor whiteColor]];
    [self addSubview:mainView];
    
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10,260, 50)];
    label.text = @"   Love Me?那就告诉全世界吧!";
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor  blueColor];
    
    UIButton *yesBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 60, 260, 50)];
    [yesBtn setBackgroundColor:[UIColor  greenColor]];
    [yesBtn setTitle:@"好!" forState:UIControlStateNormal];
    [yesBtn setTitleColor:[UIColor  redColor] forState:UIControlStateNormal];
    [yesBtn addTarget:self action:@selector(yesBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *noBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 130, 260, 50)];
    [noBtn setBackgroundColor:[UIColor redColor]];
    [noBtn setTitle:@"不,谢谢" forState:UIControlStateNormal];
    [noBtn addTarget:self action:@selector(noBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [mainView addSubview:label];
    [mainView addSubview:yesBtn];
    [mainView addSubview:noBtn];

}


- (void)yesBtnClick
{
    
    NSLog(@"YES!!!");
    [UIView animateWithDuration:0.5 animations:^{
        
        self.alpha = 0.0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}


- (void)noBtnClick
{
    NSLog(@"NO!!!");
    [UIView animateWithDuration:0.5 animations:^{
        
        self.alpha = 0.0;
        
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
    
}



@end

 

转载于:https://www.cnblogs.com/hl666/p/3701893.html

相关文章:

  • 文件的保存【OpenCV学习笔记4】
  • 清除vs2005、vs2008起始页最近打开项目
  • 51单片机-红外遥控解码
  • 汇编实验课程设计1
  • [转]实验室小科普之:方便又健康——洗水果的学问
  • C++ is on the way 8: 类初始化列表的分析总结
  • 异步DNS解析的实现
  • 图像绘制功能【OpenCV学习笔记5】
  • nopCommerce 3.3正式发布及新增功能改进
  • 对视频流进行边缘检测【OpenCV学习笔记6】
  • 发布一快速开发报表的类库,让报表的开发具有前所未有的方便和快速
  • 一个实用并且确实的内核补丁--关于桥接nat的
  • PHP数据连接主键与外键!
  • 封建制度的意义
  • 读苹果开发文档时遇到瓶颈,转而花2天看了Objc基本语法
  • 07.Android之多媒体问题
  • DataBase in Android
  • el-input获取焦点 input输入框为空时高亮 el-input值非法时
  • java 多线程基础, 我觉得还是有必要看看的
  • java取消线程实例
  • Stream流与Lambda表达式(三) 静态工厂类Collectors
  • vue从创建到完整的饿了么(11)组件的使用(svg图标及watch的简单使用)
  • 互联网大裁员:Java程序员失工作,焉知不能进ali?
  • 前端技术周刊 2018-12-10:前端自动化测试
  • 温故知新之javascript面向对象
  • 一个JAVA程序员成长之路分享
  • Nginx实现动静分离
  • TPG领衔财团投资轻奢珠宝品牌APM Monaco
  • #Linux(make工具和makefile文件以及makefile语法)
  • $forceUpdate()函数
  • (2)MFC+openGL单文档框架glFrame
  • (webRTC、RecordRTC):navigator.mediaDevices undefined
  • (附源码)php新闻发布平台 毕业设计 141646
  • (附源码)计算机毕业设计ssm基于Internet快递柜管理系统
  • (剑指Offer)面试题41:和为s的连续正数序列
  • (原创)攻击方式学习之(4) - 拒绝服务(DOS/DDOS/DRDOS)
  • .NET Core实战项目之CMS 第十二章 开发篇-Dapper封装CURD及仓储代码生成器实现
  • .net 流——流的类型体系简单介绍
  • .NET/ASP.NETMVC 深入剖析 Model元数据、HtmlHelper、自定义模板、模板的装饰者模式(二)...
  • .NET单元测试
  • .Net下使用 Geb.Video.FFMPEG 操作视频文件
  • /dev/sda2 is mounted; will not make a filesystem here!
  • @for /l %i in (1,1,10) do md %i 批处理自动建立目录
  • [ Linux 长征路第五篇 ] make/Makefile Linux项目自动化创建工具
  • [ 蓝桥杯Web真题 ]-布局切换
  • [4.9福建四校联考]
  • [AI]文心一言爆火的同时,ChatGPT带来了这么多的开源项目你了解吗
  • [autojs]逍遥模拟器和vscode对接
  • [CSAWQual 2019]Web_Unagi ---不会编程的崽
  • [C语言]——函数递归
  • [ffmpeg] av_opt_set 解析
  • [flask] flask的基本介绍、flask快速搭建项目并运行
  • [HTML]Web前端开发技术6(HTML5、CSS3、JavaScript )DIV与SPAN,盒模型,Overflow——喵喵画网页
  • [LWC] Components Communication
  • [pytest] 运行方式、常用参数、前后置条件