swift 4.2 中Picker视图覆盖了模糊效果的值
Picker view overwrites the value of blur effect in swift 4.2
我想使用 pickerview 增加或减少照片中的模糊效果级别。即使我降低该值,它也会为其添加连续的模糊效果。我该怎么办?
正在研究最新的 Swift 和 Xcode
class ViewController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource {
@IBOutlet var bg: UIImageView!
@IBOutlet var pickView: UIPickerView!
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return arr.count
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
switch arr[row] {
case "1":
Blur(blur: 0.3)
case "2":
Blur(blur: 0.6)
case "3":
Blur(blur: 0.0)
default:
print("not change")
}
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return arr[row]
}
let arr = ["1","2","3"]
override func viewDidLoad() {
super.viewDidLoad()
pickView.dataSource = self
pickView.delegate = self
// Do any additional setup after loading the view, typically from a nib.
}
func Blur(blur:CGFloat)
{
let blurEffect = UIBlurEffect(style: UIBlurEffect.Style.light)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = bg.bounds
blurView.alpha = blur
self.view.addSubview(blurView)
}
}
您的 Blur(blur: 0.3)
是函数而不是对象 class,它将 运行 不更改属性。你的 func 添加了一个子视图到你的父视图,但是 none 代码行在添加另一个之前删除它。所以它会堆叠起来。
- 删除旧的模糊子视图然后添加新的。
- 先创建一个默认的模糊视图,然后更改它的属性。
我想使用 pickerview 增加或减少照片中的模糊效果级别。即使我降低该值,它也会为其添加连续的模糊效果。我该怎么办?
正在研究最新的 Swift 和 Xcode
class ViewController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource {
@IBOutlet var bg: UIImageView!
@IBOutlet var pickView: UIPickerView!
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return arr.count
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
switch arr[row] {
case "1":
Blur(blur: 0.3)
case "2":
Blur(blur: 0.6)
case "3":
Blur(blur: 0.0)
default:
print("not change")
}
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return arr[row]
}
let arr = ["1","2","3"]
override func viewDidLoad() {
super.viewDidLoad()
pickView.dataSource = self
pickView.delegate = self
// Do any additional setup after loading the view, typically from a nib.
}
func Blur(blur:CGFloat)
{
let blurEffect = UIBlurEffect(style: UIBlurEffect.Style.light)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = bg.bounds
blurView.alpha = blur
self.view.addSubview(blurView)
}
}
您的 Blur(blur: 0.3)
是函数而不是对象 class,它将 运行 不更改属性。你的 func 添加了一个子视图到你的父视图,但是 none 代码行在添加另一个之前删除它。所以它会堆叠起来。
- 删除旧的模糊子视图然后添加新的。
- 先创建一个默认的模糊视图,然后更改它的属性。