如何解决Swift UIBlurEffect无值问题?

时间:2020-06-18 08:01:56

标签: ios swift uiblureffect

我试图在Swift 5中运行由Swift 2.x构建的代码。接受所有自动更正后,我在Simulator中遇到以下错误。

libMobileGestalt MobileGestalt.c:890:MGIsDeviceOneOfType不是 在该平台上受支持。

遵循Unable to look up screen scale and Unexpected physical screen orientation in Xcode 10后,以上错误已解决。

单击屏幕后,出现致命错误,如下所示。

致命错误:在隐式展开一个 可选值2020-06-18 16:54:37.731504 + 0900测试[81264:17199215] 致命错误:意外发现nil,同时隐式展开 可选值(lldb)

错误与

有关

updateBlurViewHole(点:moved_point,blurView:blurView)

我错过了任何必要的故事板对象吗? 我按照

中的说明进行操作
//
//  ViewController.swift
//  test
//
//  Created by June Kang on 6/18/20.
//  Copyright © 2020 June Kang. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    @IBOutlet var blurView: UIVisualEffectView!
    let context = CIContext()


    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        //updateBlurViewHole()
    }

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        //self.updateBlurViewHole(point)
    }

    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        var moved_point = CGPoint(x: 0, y: 0)
        for touch in touches {
            moved_point = touch.location(in: view)
        }
        updateBlurViewHole(point: moved_point, blurView: blurView)
    }

    func updateBlurViewHole(point: CGPoint, blurView: UIVisualEffectView) {

        let maskView = UIView(frame: blurView.bounds)
        maskView.clipsToBounds = true;
        maskView.backgroundColor = UIColor.clear

        let outerbezierPath = UIBezierPath.init(roundedRect: blurView.bounds, cornerRadius: 0)
        let rect = CGRect(x: point.x, y: point.y, width: 100, height: 100)
        let innerCirclepath = UIBezierPath.init(roundedRect:rect, cornerRadius:rect.height * 0.5)

        outerbezierPath.append(innerCirclepath)
        outerbezierPath.usesEvenOddFillRule = true



        let fillLayer = CAShapeLayer()
        fillLayer.fillRule = CAShapeLayerFillRule.evenOdd
        fillLayer.fillColor = UIColor.green.cgColor // any opaque color would work
        fillLayer.path = outerbezierPath.cgPath
        maskView.layer.addSublayer(fillLayer)
        blurView.mask = maskView;

    }
}

0 个答案:

没有答案