简单弹出视图

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

#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

简单弹出视图,码迷,mamicode.com

时间: 2024-08-16 10:51:14

简单弹出视图的相关文章

弹出视图集合

1,SemiModalViewController:  https://github.com/kentnguyen/KNSemiModalViewControllerUIViewController+KNSemiModal 致力于is an effort to make a replica of semi-modal view with pushed-back stacked animation found in the beautiful 2,TSPopover: https://github

jquery 简单弹出层

预定义html代码:没有 所有代码通过js生成和移除. 预定义css /* 基本弹出层样式 */ .my-popup-overlay { width:100%; height:auto; /* width height is defined by javascript */ position: absolute; top:0; left: 0; z-index: 1000; background-color: #000; opacity: 0.2; *filter:alpha(opacity=2

jquery 简单弹出层(转)

预定义html代码:没有 所有代码通过js生成和移除. 预定义css /* 基本弹出层样式 */ .my-popup-overlay { width:100%; height:auto; /* width height is defined by javascript */ position: absolute; top:0; left: 0; z-index: 1000; background-color: #000; opacity: 0.2; *filter:alpha(opacity=2

iOS实现自定义的弹出视图(popView)

前段时间,在项目中有个需求是支付完成后,弹出红包,实现这么一个发红包的功能.做了最后,实现的效果大致如下: 一.使用方法 整个ViewController的代码大致如下 // //  SecondViewController.m //  HWPopTool // //  Created by HenryCheng on 16/1/11. //  Copyright © 2016年 www.igancao.com. All rights reserved. // #import "SecondVi

IOS弹出视图 LewPopupViewController

LewPopupViewController是一款IOS弹出视图软件.iOS 下的弹出视图.支持iPhone/iPad. 软件截图 使用方法 弹出视图 1 2 3 4 5 PopupView *view = [PopupView defaultPopupView]; view.parentVC = self; [self lew_presentPopupView:view animation:[LewPopupViewAnimationFade new] dismissed:^{ NSLog(@

iOS开发-微信右侧弹出视图实现

微信首页的+号,点击之后会弹出一个更多的视图,这个视图如何实现呢? 实现该效果可能需要以下技术要点: 1.图片拉伸,通过拉伸图片的中间的较小区域来保持图片的边上的形状 2.仿射变换,用到仿射变换的缩放,平移和合并,视图动画 3.navigationBar的样式设置 实现效果,如下: 本Demo图片来源微信安装包解压得到的图片 实现代码: // // ViewController.m // appXX-微信更多工具栏 // // Created by MRBean on 15/7/27. // C

Cocos2d-x lua 封装的一个简单弹出框

..有2种类型:只有确定按钮.有确定和取消按钮 确定和取消按钮中的确定可以执行回调函数,标签可以自动换行,前提是在IOS模拟器上运行,mac下的模拟器看不出效果,功能比较简单,基本功能是实现了,交互上不是很好,还得改进,点击对话框外面的区域,对话框也会消失,可自行修改实现自己的需求. 继承于Layer,用类的方式写的,写的不是很好,望大神们多多指教. 代码奉上,比较简单: require "Cocos2d" require "Cocos2dConstants" --

适配移动端的简单弹出框居中效果

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title></title> 5 <style type="text/css"> 6 #mask_box { 7 width:100%; 8 height:100%; 9 z-index:9999; 10 position:fixed; 11 top:0; 12 left:0; 13 display: none; 14 } 15 #Dia

自写简单弹出框

今天下午没事,就想起自己要写个弹出框试试.首先在网上搜了哈加上了自己的一些想法,结果达到了自己预想的结果. 实现原理: 1.在页面中创建一个div. 2.将此div的position设置为absolute,并设置其left.top.width.height属性. 3.设置此div的z-index为一个较大值,以保证覆盖弹出层底下的元素. 4.通过div的显示和隐藏达到弹出效果. 直接上代码吧!为了大家方便测试,我已经将js和css都放在html中了. 注意:需要自己引入jquery.min.js