自定义封装进度提示框《MrLoadView》
来源:互联网 发布:收购淘宝店铺可信吗 编辑:程序博客网 时间:2024/06/06 04:47
封装MrLoadView类: MrLoadView程序源代码下载
**效果图:**
// 关键代码 /** 初始化UI布局 */ func setUI() { if(self.titleLabel != nil) { self.titleLabel!.removeFromSuperview() } // 底部的灰色layer let bottomShapeLayer = CAShapeLayer() bottomShapeLayer.strokeColor = self.bottomColor.CGColor bottomShapeLayer.fillColor = UIColor.clearColor().CGColor bottomShapeLayer.lineWidth = MrShapeLayerLineWidth // 图形的路径 bottomShapeLayer.path = UIBezierPath(roundedRect: CGRect(x: MrShapeLayerMargin, y: 0, width: MrShapeLayerWidth, height: MrShapeLayerWidth), cornerRadius: MrShapeLayerRadius).CGPath self.layer.addSublayer(bottomShapeLayer) // 橘黄色的layer let ovalShapeLayer = CAShapeLayer() ovalShapeLayer.strokeColor = self.animationColor.CGColor ovalShapeLayer.fillColor = UIColor.clearColor().CGColor ovalShapeLayer.lineWidth = MrShapeLayerLineWidth // 分割点效果 ovalShapeLayer.lineDashPattern = [6, 3] ovalShapeLayer.path = UIBezierPath(roundedRect: CGRect(x: MrShapeLayerMargin, y: 0, width: MrShapeLayerWidth, height: MrShapeLayerWidth), cornerRadius: MrShapeLayerRadius).CGPath self.layer.addSublayer(ovalShapeLayer) // 起点动画 let strokeStartAnimation = CABasicAnimation(keyPath: "strokeStart") strokeStartAnimation.fromValue = -1 strokeStartAnimation.toValue = 1.0 // 终点动画 let strokeEndAnimation = CABasicAnimation(keyPath: "strokeEnd") strokeEndAnimation.fromValue = 0.0 strokeEndAnimation.toValue = 1.0 // 组合动画 let animationGroup = CAAnimationGroup() animationGroup.animations = [strokeStartAnimation, strokeEndAnimation] animationGroup.duration = (Double)(MrAnimationDurationTime) animationGroup.repeatCount = (Float)(CGFloat.max) // 设置保存动画的最新状态 animationGroup.fillMode = kCAFillModeForwards // 设置动画执行完毕之后不删除动画 animationGroup.removedOnCompletion = false // 添加核心动画到layer ovalShapeLayer.addAnimation(animationGroup, forKey: nil) self.titleLabel = UILabel() self.titleLabel!.frame = CGRectMake(0, MrShapeLayerWidth + 5, MrLoadingViewWidth + 10, 30) self.titleLabel!.numberOfLines = 0 self.titleLabel!.text = self.message self.titleLabel!.textColor = MrLoadingTextColor self.titleLabel!.font = UIFont.systemFontOfSize(12) self.titleLabel!.textAlignment = NSTextAlignment.Center self.addSubview(self.titleLabel!) } /** 显示加载动画 */ func showLoadingView() { if(isShowing == true) { // 如果没有退出动画, 就不能继续添加 return } isShowing = true self.addSelfViewToWindow() } /** 关闭加载动画 */ func dismissLoadingView() { if(isShowing == false) { return } isShowing = false self.removeFromSuperview() } /** 显示加载动画(带毛玻璃效果) */ func showLoadingViewWithBlur() { if(isShowing == true) { // 如果没有退出动画,就不能继续添加 return } isShowing = true self.addSelfViewToWindow() // 拿到主窗口 let window = UIApplication.sharedApplication().keyWindow // view的x let viewCenterX: CGFloat = CGRectGetWidth(UIScreen.mainScreen().bounds)/2 // view的Y let viewCenterY: CGFloat = CGRectGetHeight(UIScreen.mainScreen().bounds)/2 // 初始化模糊效果 blurView = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.Light)) blurView?.layer.cornerRadius = 10 blurView?.layer.masksToBounds = true blurView?.frame = CGRectMake(0, 0, 100, 100) blurView?.center = CGPointMake(viewCenterX, viewCenterY) /** 添加毛玻璃效果 */ window?.insertSubview(blurView!, belowSubview: self) } /** 将本身添加到主窗口 */ func addSelfViewToWindow() { // 拿到主窗口 let window = UIApplication.sharedApplication().keyWindow // view的x let viewCenterX: CGFloat = CGRectGetWidth(UIScreen.mainScreen().bounds)/2 // view的Y let viewCenterY: CGFloat = CGRectGetHeight(UIScreen.mainScreen().bounds)/2 self.frame = CGRectMake(0, 0, MrLoadingViewWidth, MrLoadingViewWidth) self.center = CGPointMake(viewCenterX, viewCenterY) // 添加到主窗口中去 window?.addSubview(self) }}
使用测试:
func showLoadView(sender: UIButton) { let loadView = MrLoadView.sharedInstance// loadView.message = "努力加载中..."// loadView.animationColor = UIColor.greenColor()// loadView.bottomColor = UIColor.grayColor() loadView.showLoadingViewWithBlur() } func dismissLoadView(sender: UIButton) { MrLoadView.sharedInstance.dismissLoadingViewWithBlur() } override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { MrLoadView.sharedInstance.dismissLoadingViewWithBlur() }
0 0
- 自定义封装进度提示框《MrLoadView》
- Android自定义View之进度条(带进度提示框)
- android 网络加载提示进度封装 View
- Android自定义进度框
- 自定义实现简单的ios风格的弹窗加载进度框,一步步走向封装
- Android确认提示框界面自定义及封装
- 自定义ProgressDialog下载进度框
- Android 自定义加载进度框
- 自定义控件,Android实现图片加载进度提示
- SeekBar实现实现进度提示随thum移动,自定义View
- swift3.0 实现自定义圆环进度提示效果
- 自定义SeekBar实现实现进度提示随thum移动
- 自定义进度
- AlertDialog 提示框 | ProgressDialog 进度对话框
- 封装GridView实现类似ListView添加页脚,分页加载数据进度提示
- 进度环组件封装
- js模拟alert封装自定义提示框,1秒后自动消失
- Android自定义Dialog显示进度框
- 位图、图像(openGL)
- BZOJ 3932 [CQOI2015]任务查询系统 可持久化线段树
- C++成员变量初始化
- CSS:position:fixed使用
- windows 下编译libuv
- 自定义封装进度提示框《MrLoadView》
- BZOJ 1113: Poi2008海报PLA(单调栈)
- iOS网络编程:一 、GET方式同步请求
- Spring中 <tx:advice/> 标签
- 黑马程序员_IO流的概述和字符流
- IP 组播
- 安装NumPy和SciPy
- Remove Element
- 如何搭建Python3.4+Selenium