Swift.类微博弹出动画

效果图

实现效果:

view弹出时:背景渐变展示,有毛玻璃效果.view内部的button依次从上方弹到指定frame.

view消失时:背景渐变消失,view内部button依次向上方弹出.

总结实现方式:

1.弹出一个view,首先增加他的渐变效果.

2.添加毛玻璃效果.

3.添加按钮的弹出效果.

4.添加按钮回调.

5.添加type,功能优化.


1.添加view进入退出的渐变效果.

给UIView添加一个类拓展,添加进入页面和退出页面的渐变方法

extension UIView {
    ///进入页面渐变效果
    func fadeInWithTime(time:TimeInterval){
        self.alpha = 0
        UIView.animate(withDuration: time, animations: {
            self.alpha = 1
        }) { (finished) in
        }
    }
    ///退出页面渐变效果
    func fadeOutWithTime(time:TimeInterval){
        self.alpha = 1
        UIView.animate(withDuration: time, animations: {
            self.alpha = 0
        }) { (finished) in
            self.removeFromSuperview()
        }
    } 
}

2.添加毛玻璃效果

    func drawMyView()  {
        //首先创建一个模糊效果
        let blurEffect = UIBlurEffect(style: .light)
        //接着创建一个承载模糊效果的视图
        let blurView = UIVisualEffectView(effect: blurEffect)
        //设置模糊视图的大小(全屏)
        blurView.frame.size = CGSize(width: self.frame.width, height: self.frame.height)
        //添加模糊视图到页面view上(模糊视图下方都会有模糊效果)
        self.addSubview(blurView)
    }

3.添加按钮的弹出效果

将按钮加入contentArr. 在view显示和退出时调用这两个方法

//popview展示动画
    func moveInAnimation(){
        for (index,value) in (contentArr.enumerated()){
            let btn:UIButton = value
            let x = btn.frame.origin.x
            let y = btn.frame.origin.y
            let width = btn.frame.size.width
            let height = btn.frame.size.height
            btn.frame = CGRect(x: x, y: 10, width: width, height: height)
            btn.alpha = 0.0

            DispatchAfter(after: (Double(index) * 0.05)) {
                UIView.animate(withDuration: 0.25, delay: 0, usingSpringWithDamping: 0.75, initialSpringVelocity: 25, options: .curveEaseIn, animations: {
                    btn.alpha = 1
                    btn.frame = CGRect(x: x, y: y, width: width, height: height)
                }, completion: { (finished) in
                    if (btn.isEqual(self.contentArr.last)){
                        self.superview?.superview?.isUserInteractionEnabled = true
                    }
                })
            }
        }
    }
    //popview退出动画
    func moveOutAnimation(){
        for (index,value) in (contentArr.enumerated()){
            let btn:UIButton = value
            let x = btn.frame.origin.x
            let y = btn.frame.origin.y
            let width = btn.frame.size.width
            let height = btn.frame.size.height
            btn.frame = CGRect(x: x, y: y, width: width, height: height)
            btn.alpha = 1

            DispatchAfter(after: (Double(index) * 0.05)) {
                UIView.animate(withDuration: 0.25, delay: 0, usingSpringWithDamping: 0.75, initialSpringVelocity: 25, options: .curveEaseIn, animations: {
                    btn.alpha = 0
                    btn.frame = CGRect(x: x, y: 10, width: width, height: height)
                }, completion: { (finished) in
                    if (btn.isEqual(self.contentArr.last)){
                        self.superview?.superview?.isUserInteractionEnabled = true
                    }
                })
            }
        }
    }

4.添加按钮回调

    var backBlockLeft : (()->())?//左侧按钮点击事件
    var backBlockRight : (()->())?//右侧按钮点击事件

    //点击左右button事件
    @objc func onClickButton(_ button:UIButton){
        if button.tag  == 0 {
            if backBlockLeft != nil{
                backBlockLeft!()
            }
        }else {
            if backBlockRight != nil{
                backBlockRight!()
            }
        }
    }

5.添加type,功能优化.

添加type,实现popview的复用.

//popView两种Type,通过修改type来实现不同样式
enum popViewType{
    case left//概况
    case right//发布
}

 private var type:popViewType = .left {
        didSet {
            switch type {
            case .left:
                leftButtonTitle = "历史"
                leftButtonImage = "lishi"
                rightButtonTitle = "今天"
                rightButtonImage = "jintian"
            case .right:
                leftButtonTitle = "政策"
                leftButtonImage = "zuixinzhengce"
                rightButtonTitle = "快报"
                rightButtonImage = "jdkb"
            }
        }
    }

  init(frame: CGRect,type:popViewType) {
        super.init(frame: frame)
        //在init方法中直接赋值不能调用didSet方法,使用kvo方式赋值
        self.setValue(type, forKey: "type")
        drawMyView()
        addTap()
        addBtn()
    }

 //重写kvo方法才能完成赋值,不然报错
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        guard let type = value as? popViewType else {
            return
        }
        self.type = type
    }


demo地址:PopView.求star.

有问题欢迎探讨.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JavaSwift JOSS是一个Java语言的Swift对象存储接口,可以用来访问Swift对象存储服务。使用JavaSwift JOSS需要进行以下步骤: 1. 在你的项目中引入JavaSwift JOSS的依赖库,可以使用Maven或Gradle等构建工具进行依赖管理。 2. 创建Swift对象存储服务的连接。使用以下代码创建连接: ``` SwiftConfig config = new SwiftConfig() .withCredentials(new Credentials("username", "password")) .withEndpoint("http://swift.example.com/auth/v1.0") .withTenantName("tenantName"); Swift swift = new SwiftImpl(config); ``` 其中,username和password是Swift对象存储服务的用户名和密码,http://swift.example.com/auth/v1.0是Swift服务的地址,tenantName是你的租户名称。 3. 使用Swift对象存储服务进行文件的上传、下载、删除等操作。以下是一些常见操作的示例: 上传文件: ``` SwiftObject object = swift.objects().put("containerName", "objectName", new byte[] {0, 1, 2, 3}); ``` 其中,containerName是Swift存储容器的名称,objectName是文件名称,new byte[] {0, 1, 2, 3}是文件内容。 下载文件: ``` SwiftObject object = swift.objects().get("containerName", "objectName"); byte[] content = object.downloadContent(); ``` 其中,containerName和objectName均为要下载的文件的名称。 删除文件: ``` swift.objects().delete("containerName", "objectName"); ``` 其中,containerName和objectName均为要删除的文件的名称。 以上是JavaSwift JOSS的基本使用方法,你可以根据自己的需要进行更多的操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值