ios - removeFromSuperview() 不工作

标签 ios swift uiblureffect

我想在询问触摸 ID 时模糊背景,一旦授权成功,viewcontroller 需要可见。但这没有发生。即使授权成功,viewcontroller 仍然模糊。谁能帮我如何解决这个问题?

import UIKit
import LocalAuthentication
class TabBarViewController: UITabBarController {

@IBOutlet weak var noteTabBar: UITabBar!

override func viewDidLoad() {
super.viewDidLoad()
    self.authenticateUser()
    self.tabBar.hidden = false
    self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())

    let userDefaults = NSUserDefaults.standardUserDefaults()
    userDefaults.setObject(false, forKey: "sendModeToggle")
    userDefaults.setObject("Avenir-Medium", forKey: "font")
     userDefaults.setObject(13, forKey:"fontSize")
            // Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

// MARK: Touch ID Authentication

func authenticateUser()
{
    let context = LAContext()
    var error: NSError?
    let reasonString = "Authentication is needed to access your app! :)"

    let blurEffect = UIBlurEffect(style: .Light)
    let blurVisualEffectView = UIVisualEffectView(effect: blurEffect)
    blurVisualEffectView.frame = view.bounds
    self.view.addSubview(blurVisualEffectView)

    if context.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &error)
    {

        context.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: reasonString, reply: { (success, policyError) -> Void in

            if success
            {
                print("Authentication successful! :) ")
                blurVisualEffectView.removeFromSuperview()

            }
            else
            {
                switch policyError!.code
                {
                case LAError.SystemCancel.rawValue:
                    print("Authentication was cancelled by the system.")
                /*case LAError.UserCancel.rawValue:
                    print("Authentication was cancelled by the user.")
                 */   
                case LAError.UserFallback.rawValue:
                    print("User selected to enter password.")
                    NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
                        self.showPasswordAlert()
                        blurVisualEffectView.removeFromSuperview()

                    })
                default:
                    print("Authentication failed! :(")
                    NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
                        self.showPasswordAlert()
                        blurVisualEffectView.removeFromSuperview()

                    })
                }
            }

        })

    }
    else
    {
        print(error?.localizedDescription)
        NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
            self.showPasswordAlert()
        })
    }


}

}

最佳答案

由于您要在闭包中删除 View ,因此您可能不在主线程中。尝试将删除代码分派(dispatch)到主线程:

if success {
    print("Authentication successful! :) ")
    dispatch_async(dispatch_get_main_queue()) {
        blurVisualEffectView.removeFromSuperview()
    }
}

关于ios - removeFromSuperview() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38635447/

相关文章:

ios - 旋转 UIImageView

ios - 单击注释时如何访问可用数据?

iphone - cameraOverlayView 在 UIImagePickerController 中裁剪结果

ios - 如何减少 UIVisualEffectView 上的模糊效果

ios - 如何使用标志禁用 Crashlytics iOS 库?

ios - 将位置数据 POST 到接收多个条目的服务器

ios - 使用 AVCapturePhotoOutput 使用闪光灯拍照时出现问题

ios - iPhone:将imageView设置在图像的透明部分

xcode6 - 如何禁用项目导航器的透明度?