zoukankan      html  css  js  c++  java
  • [Xcode 实际操作]六、媒体与动画-(6)使用UIBlurEffect给图片添加模糊效果

    目录:[Swift]Xcode实际操作

    本文将演示如何给图像添加模糊效果。

    在项目导航区,打开视图控制器的代码文件【ViewController.swift】

     1 import UIKit
     2 
     3 class ViewController: UIViewController {
     4 
     5     override func viewDidLoad() {
     6         super.viewDidLoad()
     7         // Do any additional setup after loading the view, typically from a nib.
     8         
     9         //从项目资源文件中加载一张图片
    10         let image = UIImage(named: "Picture")
    11         //创建一个图像视图对象,
    12         //并给图像视图指定需要显示的图片
    13         let imageView = UIImageView(image: image)
    14         //将图像视图,添加到当时视图控制器的根视图
    15         self.view.addSubview(imageView)
    16         
    17         //从iOS8.0版本开始,系统提供了模糊效果的功能。
    18         //这里判断如果系统版本号大于等于8.0,则使用模糊效果
    19         if #available(iOS 8.0, *)
    20         {
    21             //初始化一个模糊效果对象。
    22             //模糊效果对象可以帮助快速制作雷系与导航栏、通知中心或控制中心的毛玻璃效果
    23             let blur = UIBlurEffect(style: .light)
    24             //初始化一个基于模糊效果的视觉效果视图
    25             let blurView = UIVisualEffectView(effect: blur)
    26             //设置设置模糊效果的位置为(55,75),尺寸为(200,200)
    27             blurView.frame = CGRect(x: 55, y: 75,  200, height: 200)
    28             //设置模糊视图的圆角半径为30
    29             blurView.layer.cornerRadius = 30
    30             //设置模糊视图的遮罩覆盖属性,进行边界裁切
    31             blurView.layer.masksToBounds = true
    32             //将模糊视图添加到图像视图,作为图像视图的子视图
    33             imageView.addSubview(blurView)
    34         }
    35         else
    36         {
    37             print("UIBlurEffect is only available on iOS8.0 or later.")
    38         }
    39     }
    40 
    41     override func didReceiveMemoryWarning() {
    42         super.didReceiveMemoryWarning()
    43         // Dispose of any resources that can be recreated.
    44     }
    45 }
  • 相关阅读:
    ElasticSearch工作原理
    prometheus监控es集群
    es索引调优
    ES中Refresh和Flush的区别
    网络服务器技术Apache与Nginx,IIS的不同
    shell里/dev/fd与/proc/self/fd的区别
    常用抓包工具
    Ubuntu Kubuntu Xubuntu Lubuntu Dubuntu Mythbuntu UbuntuBudgie区别
    Android的Looper.loop()消息循环机制
    申请读写sd卡权限shell
  • 原文地址:https://www.cnblogs.com/strengthen/p/10034363.html
Copyright © 2011-2022 走看看