swift 自定义弹框

//

//  ViewController.swift

//  animationAlert

//

//  Created by su on 15/12/9.

//  Copyright © 2015年 tian. All rights reserved.

//

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {

super.viewDidLoad()

//灰色的遮挡板

let overLayView = UIView(frame: self.view.bounds)

overLayView.backgroundColor = UIColor.blackColor()

overLayView.alpha = 0

//加入场景

self.view.addSubview(overLayView)

//警告框相关的代码

//警告框的宽度

let alerDimension:CGFloat = 250

let alertViewFrame = CGRect(x: self.view.bounds.size.width / 2 - alerDimension / 2, y: self.view!.bounds.size.height / 2 - alerDimension / 2, width: alerDimension, height: alerDimension)

let alertView  = UIView(frame: alertViewFrame)

alertView.backgroundColor = UIColor(patternImage: UIImage(named: "alert_box")!)

alertView.alpha = 1

//警告框初始尺寸为1.2 倍

alertView.transform = CGAffineTransformMakeScale(1.2, 1.2)

//设置圆角半径

alertView.layer.cornerRadius = 10

//设置阴影

//颜色

alertView.layer.shadowColor = UIColor.blackColor().CGColor

//阴影偏移

alertView.layer.shadowOffset = CGSizeMake(0, 5)

//阴影透明度

alertView.layer.shadowOpacity = 0

//阴影的半径

alertView.layer.shadowRadius = 10

self.view.addSubview(alertView)

//延时设置

var minseconds = 1 * Double(NSEC_PER_MSEC)

var dtime = dispatch_time(DISPATCH_TIME_NOW, Int64(minseconds))

dispatch_after(dtime, dispatch_get_main_queue()) { () -> Void in

//自定义警告框动画的上半部分

UIView.animateWithDuration(0.3, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in

overLayView.alpha = 0.3

alertView.alpha = 1

}, completion: nil)

let scale = JNWSpringAnimation(keyPath: "transform.scale")

scale.damping = 14

scale.stiffness = 14

scale.mass = 1

scale.fromValue = 1.2

scale.toValue = 1

alertView.layer.addAnimation(scale, forKey: scale.keyPath)

alertView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1)

}

minseconds = 3 * Double(NSEC_PER_MSEC)

dtime = dispatch_time(DISPATCH_TIME_NOW, Int64(minseconds))

dispatch_after(dtime, dispatch_get_main_queue()) { () -> Void in

//下半部分消失

UIView.animateWithDuration(1, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in

overLayView.alpha = 0

alertView.alpha = 0

}, completion: nil)

let scaleOut = JNWSpringAnimation(keyPath: "tranform.scale")

scaleOut.damping = 14

scaleOut.stiffness = 14

scaleOut.mass = 1

scaleOut.fromValue = 1

scaleOut.toValue = 0.7

alertView.layer.addAnimation(scaleOut, forKey: scaleOut.keyPath)

alertView.transform = CGAffineTransformMakeScale(0.7, 0.7)

}

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

时间: 2024-08-02 06:55:21

swift 自定义弹框的相关文章

简单的自定义弹框

作为初学者,很多人都是用的系统自带的弹框,非常的简单,完全不能满足用户的交互,所以这里,我们需要自定义一个弹框,把输入框.图片.按钮等添加到弹框里面.为了避免重复冗余的代码,参考了别人的代码,自己做了一个自定义弹框,可以在项目中使用到.给大家一个思路. 这是代码的接口定义,只需要调用一行代码就可以弹出一个自定义的视图啦.还会添加一些动画效果,让弹框弹出跟消失更美观. + (void)showPromptBoxWithCustomView:(UIView *)customView; + (void

Windows Phone开发学习笔记(1)---------自定义弹框

Windows Phone开发学习笔记(1) ---------自定义弹框 在WP中自定义弹框是可以通过Popup类实现的. Popup的语法为: [ContentPropertyAttribute("Child")] [LocalizabilityAttribute(LocalizationCategory.None)] public class Popup : FrameworkElement, IAddChild; 这是Popup使用的小列子 Popup codePopup =

自定义弹框加载方式

- (void)show { if ([UIApplication sharedApplication].keyWindow.rootViewController.navigationController) { [[UIApplication sharedApplication].keyWindow.rootViewController.navigationController.view addSubview:self]; }else{ [[UIApplication sharedApplica

js组件--自定义弹框

javascript自定义弹框 性能太差,有很大的改善空间 1 <!doctype html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 <!--<link href="styles/reset.css" type="text/css&

自定义弹框

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv=&q

RN code push自定义弹框

最近在弄react native的code push热更新问题.开始是用的后台默默更新配置.由于微软服务器速度问题,经常遇到用户一直在下载中问题.而用户也不知道代码需要更新才能使用新功能,影响了正常业务流程.而目前公司也无力搭建自己的服务器和dns设置.所以比较快速的方案就是,前端自定义热更新弹框,在需要更新代码的情况下禁止用户向下操作. ok,废话少说,直接上代码: 这是构建一个弹框,强制文案提示和非强制文案提示弹框. /** * Created by susie on 2018/9/20.

html自定义弹框

一.要实现的功能 1.弹框弹出时有遮罩 2.弹框内的文字过多时右侧有滚动条 3.根据执行结果变更弹框title的样式 二.具体实现 思路:定义一个有宽高的div,默认隐藏,当要显示时,设置为display=block来显示 1.定义div布局,一个遮罩层:一个弹框(弹框中有标题和内容两部分) <div id="dialogmask" class="dialogmask opacity"></div> <div id="dial

自定义弹框,点击提示框外空白区域,让弹框消失

tip: self.mainView  是提示框的全屏背景.一般是透明的黑色 self.bgImg   添加提示内容的主要view 方法一:正常情况下,各个页面都有touchesBegan:withEvent事件的触发.使用该方法 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; // 计算搜索框范围 CGPoint touchPoint

android之自定义弹框

step1 创建窗体 final AlertDialog dialog =new Builder(this).create(); step2 获取View View viewDialog =View.inflate(this, R.layout.userinfo_dialog_edit, null); final EditText txtUserName=(EditText)viewDialog.findViewById(R.id.txtUserName); final EditText txt