• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

swift自定义弹框

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

//

//  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.

    }

 

 

}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
[Swift]LeetCode249.群组偏移字符串$GroupShiftedStrings发布时间:2022-07-13
下一篇:
Swift实战-豆瓣电台(七)显示动画发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap