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 }
  • 相关阅读:
    LeetCode第[66]题(Java):Plus One
    LeetCode第[62]题(Java):Unique Paths 及扩展
    localhost不能访问127.0.0.1可以访问的原因以及解决办法
    LeetCode第[56]题(Java):Merge Intervals
    LeetCode第[55]题(Java):Jump Game
    LeetCode第[54]题(Java):Spiral Matrix
    LeetCode第[53]题(Java):Maximum Subarray
    LeetCode第[50]题(Java):Pow(x, n)
    LeetCode第[49]题(Java):Group Anagrams
    Keras 资源
  • 原文地址:https://www.cnblogs.com/strengthen/p/10034363.html
Copyright © 2011-2022 走看看