gpt4 book ai didi

ios - FirebaseAuthUI IOS - 如何添加登录屏幕背景图片?

转载 作者:行者123 更新时间:2023-11-28 06:12:45 26 4
gpt4 key购买 nike

我想在登录屏幕的登录按钮后面添加一个图像。我目前收到以下错误消息:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法在包中加载 NIB:‘NSBundle <...> 名称 ...

这是我的代码:

在 AppDelegate 中:

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var authHandle: AuthStateDidChangeListenerHandle?
var userInfo:User!

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()

//checkLoggedIn
authHandle = Auth.auth().addStateDidChangeListener { auth, user in
if let user = user {
self.userInfo = user
} else {
// No user is signed in.
self.login()
}
}

return true
}

func login() {
let authUI = FUIAuth.defaultAuthUI()
authUI?.delegate = self as? FUIAuthDelegate

let providers: [FUIAuthProvider] = [
FUIFacebookAuth()
]
authUI?.providers = providers

// Present the auth view controller and then implement the sign in callback.
let authViewController = CustomAuthViewController(authUI: authUI!)
self.window?.rootViewController?.present(authViewController, animated: false, completion: nil)
}

func authPickerViewController(for authUI: FUIAuth) -> FUIAuthPickerViewController {
return CustomAuthViewController(nibName: "CustomAuthViewController",
bundle: Bundle.main,
authUI: authUI)
}
}

在 CustomAuthViewController 中:

class CustomAuthViewController: FUIAuthPickerViewController {

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.

let width = UIScreen.main.bounds.size.width
let height = UIScreen.main.bounds.size.height

let imageViewBackground = UIImageView(frame: CGRect(x: 0, y: 0, width: width, height: height))
imageViewBackground.image = UIImage(named: "myimage")

// you can change the content mode:
imageViewBackground.contentMode = UIViewContentMode.scaleToFill

view.insertSubview(imageViewBackground, at: 0)
}

你看到哪里不对了吗?我不确定 authPickerViewController 函数应该在我的 AppDelegate 中,你能确认它没问题吗?

我找到了 this发布和this one但我无法让它发挥作用。我使用 Firebase-UI 4.1.1,我的登录流程没有背景图像(因此没有 CustomPickerViewController)。

谢谢,

亚历克斯

最佳答案

这是我的自定义覆盖的样子:

import UIKit
import FirebaseAuthUI

class BizzyAuthViewController: FUIAuthPickerViewController {


override init(nibName: String?, bundle: Bundle?, authUI: FUIAuth) {
super.init(nibName: "FUIAuthPickerViewController", bundle: bundle, authUI: authUI)
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.

let width = UIScreen.main.bounds.size.width
let height = UIScreen.main.bounds.size.height

let imageViewBackground = UIImageView(frame: CGRect(x: 0, y: 0, width: width, height: height))
imageViewBackground.image = UIImage(named: "lavenderWithBees")

// you can change the content mode:
imageViewBackground.contentMode = UIViewContentMode.scaleAspectFill

view.insertSubview(imageViewBackground, at: 0)

}

}

这就是我的登录函数(在“ViewController.swift”中)的样子:

func login() {

//FirebaseApp.configure()
let authUI = FUIAuth.defaultAuthUI()
let providers: [FUIAuthProvider] = [FUIGoogleAuth(), FUIFacebookAuth()]
authUI?.providers = providers
authUI?.delegate = self as FUIAuthDelegate

let authViewController = BizzyAuthViewController(authUI: authUI!)
let navc = UINavigationController(rootViewController: authViewController)
self.present(navc, animated: true, completion: nil)

}

关于ios - FirebaseAuthUI IOS - 如何添加登录屏幕背景图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46070531/

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