gpt4 book ai didi

swift - 用户在 alertview 中按下 alternativ 后,如何消除模糊效果?

转载 作者:行者123 更新时间:2023-11-28 15:53:06 25 4
gpt4 key购买 nike

如果用户想要返回,这是出现的模糊效果和警告。我找不到任何我理解的东西所以我希望这里有人可以帮助我。感谢您的帮助!

这是所有代码,但新代码在。

       //
// Visartotal.swift
// Segment controll
//
// Created by Simon Harrysson on 2017-01-28.
// Copyright © 2017 Simon Harrysson. All rights reserved.
//

import UIKit

var Allabetygtillsamans: Double = 0


class Visartotal: UIViewController
{

@IBOutlet weak var Tillbaka: UIButton!
@IBOutlet weak var Börjaomknapp: UIButton!
@IBOutlet weak var Visartotalreligion: UILabel!
@IBOutlet weak var VisartotalIMusik: UILabel!
@IBOutlet weak var Visartotaltmerit: UILabel!
@IBOutlet weak var VisartotalBild: UILabel!
@IBOutlet weak var Visartotalmatematik:UILabel!
@IBOutlet weak var VisartotalEngelska: UILabel!

var blurEffectView: UIVisualEffectView?

override func viewDidAppear(_ animated: Bool)
{
self.blurEffect = UIBlurEffect(style: .dark)
self.blurEffectView = UIVisualEffectView(effect: self.blurEffect)
blurEffectView?.frame = view.bounds
blurEffectView?.autoresizingMask = [.flexibleWidth, .flexibleHeight] // for supporting device rotation


}
var blurEffect: UIBlurEffect?

@IBAction func TillbakaAction(_ sender: UIButton)
{
createAlert(title: "Är du säker på att du vill börja om?", message: "Ifyllda betyg nollställs")
blurEffectView = UIVisualEffectView(effect: blurEffect)

view.addSubview(blurEffectView!)
}

func createAlert (title:String, message:String)
{
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)

//CREATING ON BUTTON
alert.addAction(UIAlertAction(title: "Ja", style: UIAlertActionStyle.default, handler: {
(action) in
alert.dismiss(animated: true, completion: nil)
print ("Jag vill gå tillbaka")
self.performSegue(withIdentifier: "Tillbaka", sender: nil)
self.blurEffectView?.removeFromSuperview()

}))

alert.addAction(UIAlertAction(title: "Nej", style: UIAlertActionStyle.default, handler: { (action) in
alert.dismiss(animated: true, completion: nil)
print("Nej, jag vill inte gå tillbaka")
self.blurEffectView?.removeFromSuperview()

}))

self.present(alert, animated: true, completion: nil)



}

override func viewDidLoad()
{


let Allabetygtillsamans = MusikbetygIDouble + BildbetygValtDouble + MatematikbetygvaltIDouble + ReligionbetygvaltDouble + EngelskabetygvaltDouble

Visartotaltmerit.font = UIFont(name: "Arial", size: 21)


let totalameritet = String(Allabetygtillsamans)


VisartotalIMusik.text = MusikbetygValt
VisartotalBild.text = BildbetygValt
Visartotalmatematik.text = Matematikbetygvalt
Visartotalreligion.text = Religionbetygvalt
VisartotalEngelska.text = Engelskabetygvalt

Visartotaltmerit.text = totalameritet + ("p")


if BildbetygValt == "F"
{
VisartotalBild.textColor = UIColor.red
}
if MusikbetygValt == "F"
{
VisartotalIMusik.textColor = UIColor.red
}
if Matematikbetygvalt == "F"
{
Visartotalmatematik.textColor = UIColor.red
}
if Religionbetygvalt == "F"
{
Visartotalreligion.textColor = UIColor.red
}
if Engelskabetygvalt == "F"
{
VisartotalEngelska.textColor = UIColor.red
}



switch Allabetygtillsamans {
case 290...340:
Visartotaltmerit.textColor = UIColor.green
Visartotaltmerit.backgroundColor = UIColor.clear
Visartotaltmerit.backgroundColor = UIColor.clear
case 230...290:
Visartotaltmerit.textColor = UIColor.yellow
Visartotaltmerit.backgroundColor = UIColor.clear
Visartotaltmerit.backgroundColor = UIColor.clear
case 220...230:
Visartotaltmerit.textColor = UIColor.orange
Visartotaltmerit.backgroundColor = UIColor.clear
case 0...220:
Visartotaltmerit.textColor = UIColor.red
Visartotaltmerit.backgroundColor = UIColor.clear
default:
print("defult")
}



func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}





}
}

最佳答案

您将需要创建一个 blurEffectView 变量,您可以从 tillbakaAction 函数的范围之外访问该变量 - 在 vi​​ewController 中的某处。然后,在您的 UIAlertActions 中,您可以说 self.blurEffectView.removeFromSuperview() 来删除它。不会有动画 - 它会消失。

此外,正如另一位评论者指出的那样,您不需要说 alert.dismiss...,因为它会自动发生。

作为您的变量的示例,这将起作用:

var blurEffectView: UIVisualEffectView?

@IBAction func tillbakaAction(_ sender: UIButton) {
...
self.blurEffectView = UIVisualEffectView(effect: blurEffect)
...
}

在你的行动中:

alert.addAction(UIAlertAction(title: "Ja", style: UIAlertActionStyle.default, handler: {
(action) in
self.blurEffectView?.removeFromSuperview()
...

关于swift - 用户在 alertview 中按下 alternativ 后,如何消除模糊效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42097419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com