iOS 自定义弹出框

本文介绍如何在iOS应用中创建自定义弹窗视图,并实现显示与隐藏的动画效果。通过Swift语言,利用UIView动画,实现了弹窗的平滑过渡。

在iOS中,系统再带的弹出窗体不好扩展,开发时候不如自定义一个弹出窗体,附加上显示和消失的动画。 输入图片说明

弹出窗体父类如下,具体效果直接往上面添加控件就行。 // // ViewController.swift // NoahSalesManage // // Created by Administrator on 15/3/5. // Copyright (c) 2015年 cdwlb-zhangzhengfa. All rights reserved. //

import UIKit

class BounceView:UIControl {

var contentView:UIControl?;

override init(frame: CGRect) {
    super.init(frame: frame)
    self.processInterface()
}

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    self.processInterface()
}

func processInterface()
{
    
    self.backgroundColor = UIColor(white: 0, alpha: 0.8)
    
    self.contentView = UIControl(frame: CGRectInset(self.frame, 20, 40))
    self.contentView!.backgroundColor = UIColor.whiteColor()
    self.addSubview(self.contentView!)
    
    self.alpha = 0
    self.contentView!.transform = CGAffineTransformMakeScale(0.1, 0.1);
}

func showWithAnimation(animation:Bool)
{
    if !animation
    {
        self.alpha = 1
    }
    else
    {
        UIView.animateWithDuration(0.5, delay: 0, options: .CurveEaseInOut, animations: { () -> Void in
            self.alpha = 1
            self.contentView!.transform = CGAffineTransformIdentity
            }, completion: { (succss) -> Void in
                
        })
    }
}

func hideWithAnimation(animation:Bool)
{
    if !animation
    {
        self.alpha = 1
    }
    else
    {
        UIView.animateWithDuration(0.5, animations: { () -> Void in
            self.alpha = 0
            self.contentView!.transform = CGAffineTransformMakeScale(0.1, 0.1)
        })
    }
}

}

转载于:https://my.oschina.net/jesonzhang/blog/418095

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值