- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在尝试设置动画并更改闭包内 ui 元素的某些属性时遇到问题。当我尝试通过函数对某些 View 进行动画处理时,它执行该函数但动画无法完成,但是当我在闭包之外执行该函数时,它工作正常。这是我的代码,我的问题出在 AuthController 底部的委托(delegate)扩展中,函数名为 facebookAuth。我已经苦苦挣扎了将近一天了,我找不到错误。
我在动画和函数中放置了一些打印语句来追踪目的,这些是执行的语句:
Login successful (this one is in the delegate function
slide (this one is in the slide function)
not complete (this one is in the animation closure)
AuthController
import UIKit
import AVFoundation
import FBSDKLoginKit
import FBSDKCoreKit
import Firebase
protocol AuthControllerDelegate {
func login(withUser user: User)
func facebookAuth()
func signUp(withUser user: User)
func facebookRegister(withEmail email: String, cellphone: String)
}
class AuthController: UIViewController {
enum AuthView {
case registerView
case loginView
case fbRegisterSecondStepCenter
}
private var player: AVPlayer!
private var playerLayer: AVPlayerLayer!
private var registerViewCenterConstraint: NSLayoutConstraint?
private var loginViewCenterConstraint: NSLayoutConstraint?
private var fbRegisterSecondStepCenterConstraint: NSLayoutConstraint?
private var currentView: AuthView = .loginView
private var facebookUserStore: User?
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
private let purpleBackground: UIView = {
let pb = UIView()
pb.backgroundColor = .darkBackground
pb.alpha = 0.5
return pb
}()
//MARK: AuthViews
private lazy var loginView: LoginView = {
let view = LoginView()
view.delegate = self
return view
}()
private lazy var registerView: RegisterView = {
let view = RegisterView()
// view.delegate = self
view.alpha = 0
return view
}()
private lazy var fbRegisterSecondStep: FBRegisterSecondStep = {
let view = FBRegisterSecondStep()
view.alpha = 0
view.delegate = self
return view
}()
private lazy var bottomBtn: UIButton = {
let btn = UIButton()
let attributedString = NSMutableAttributedString(string: "Not registered? Sign up.", attributes: [.foregroundColor: UIColor.lightText, .font: UIFont.init(name: Fonts.lightFont.rawValue, size: 16)!])
btn.setAttributedTitle(attributedString, for: .normal)
btn.contentHorizontalAlignment = .center
btn.addTarget(self, action: #selector(handleChangeView), for: .touchUpInside)
return btn
}()
let alertController: AlertController = {
let ac = AlertController()
return ac
}()
override func viewDidLoad() {
super.viewDidLoad()
print(UserDefaults.Account.bool(forKey: .isUserLoggedIn))
setVideoBackground()
setupViews()
alertController.transitioningDelegate = alertController
alertController.modalPresentationStyle = .custom
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isNavigationBarHidden = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isNavigationBarHidden = false
}
private func setupViews() {
view.addSubview(purpleBackground)
view.addSubview(loginView)
view.addSubview(registerView)
view.addSubview(fbRegisterSecondStep)
view.addSubview(bottomBtn)
_ = purpleBackground.anchor(top: view.topAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, left: view.leftAnchor)
loginViewCenterConstraint = loginView.centerInView().first
_ = loginView.anchorWithMultiplier(top: nil, bottom: nil, right: nil, left: nil, height: view.heightAnchor, width: view.widthAnchor, topConstant: 0, bottomConstant: 0, rightConstant: 0, leftConstant: 0, widthMultiplier: 0.8, heightMultiplier: 0.6)
registerViewCenterConstraint = registerView.centerInView().first
registerViewCenterConstraint?.constant = 1000
_ = registerView.anchorWithMultiplier(top: nil, bottom: nil, right: nil, left: nil, height: view.heightAnchor, width: view.widthAnchor, topConstant: 0, bottomConstant: 0, rightConstant: 0, leftConstant: 0, widthMultiplier: 0.8, heightMultiplier: 0.8)
fbRegisterSecondStepCenterConstraint = fbRegisterSecondStep.centerInView().first
fbRegisterSecondStepCenterConstraint?.constant = 1000
_ = fbRegisterSecondStep.anchorWithMultiplier(top: nil, bottom: nil, right: nil, left: nil, height: view.heightAnchor, width: view.widthAnchor, topConstant: 0, bottomConstant: 0, rightConstant: 0, leftConstant: 0, widthMultiplier: 0.8, heightMultiplier: 0.5)
_ = bottomBtn.anchor(top: nil, bottom: view.bottomAnchor, right: view.rightAnchor, left: view.leftAnchor, topConstant: 0, bottomConstant: 20, rightConstant: 0, leftConstant: 0, widthConstant: 0, heightConstant: 0)
}
private func setVideoBackground() {
let videoPath = Bundle.main.url(forResource: "trim720", withExtension: "mp4")
player = AVPlayer(url: videoPath!)
playerLayer = AVPlayerLayer(player: player)
playerLayer.videoGravity = .resizeAspectFill
playerLayer.frame = view.frame
player.actionAtItemEnd = .none
player.play()
view.layer.insertSublayer(playerLayer, at: 0)
NotificationCenter.default.addObserver(self, selector: #selector(handleStop), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)
}
private func slide(toView view: AuthView, completion: @escaping (Bool) -> Void = { _ in }) {
guard let registerCenterConstraint = registerViewCenterConstraint, let loginCenterConstraint = loginViewCenterConstraint, let fbRegisterSecondConstraint = fbRegisterSecondStepCenterConstraint else {
fatalError("Error unwrapping auth views constraints.")
}
switch view {
case .loginView:
loginCenterConstraint.constant = 0
registerCenterConstraint.constant = 1000
fbRegisterSecondConstraint.constant = 1000
currentView = .loginView
case .registerView:
loginCenterConstraint.constant = 1000
registerCenterConstraint.constant = 0
fbRegisterSecondConstraint.constant = 1000
currentView = .registerView
case .fbRegisterSecondStepCenter:
loginCenterConstraint.constant = 1000
registerCenterConstraint.constant = 1000
fbRegisterSecondConstraint.constant = 0
currentView = .fbRegisterSecondStepCenter
print("slideeeeeeeeeeee")
}
let isRegisterVisible = registerCenterConstraint.constant == 0
let isLoginVisible = loginCenterConstraint.constant == 0
let isFbRegisterVisible = fbRegisterSecondConstraint.constant == 0
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.registerView.alpha = isRegisterVisible ? 1 : 0
self.loginView.alpha = isLoginVisible ? 1 : 0
self.fbRegisterSecondStep.alpha = isFbRegisterVisible ? 1 : 0
self.view.layoutIfNeeded()
print("slide")
}) { (state) in
if state {
print("completed")
} else {
print("not completed")
}
completion(state)
}
}
fileprivate func pushHome() {
navigationController?.isNavigationBarHidden = false
navigationController?.setViewControllers([HomeController()], animated: true)
}
// MARK: Handlers
@objc private func handleStop() {
player.seek(to: kCMTimeZero)
}
@objc private func handleChangeView() {
let isLoginVisible = currentView == .loginView
let view: AuthView = isLoginVisible ? .registerView : .loginView
slide(toView: view) { (completed) in
let attributedString = self.bottomBtn.attributedTitle(for: .normal) as! NSMutableAttributedString
let newTitle = isLoginVisible ? "Already an user? Sign In" : "Not registered? Sign up."
attributedString.mutableString.setString(newTitle)
}
}
}
extension AuthController: Loginable, Registable, AuthControllerDelegate {
func login(withUser user: User) {
signIn(withUser: user) { (_) in
self.pushHome()
}
}
func facebookAuth(){
let loginManager = FBSDKLoginManager()
loginManager.logIn(withReadPermissions: ["email", "public_profile"], from: self) { (result, err) in
if err == nil, !(result?.isCancelled)!, let token = result?.token.tokenString {
print("Login successful")
self.loginView.isHidden = true
self.bottomBtn.isHidden = true
self.slide(toView: .registerView)
}
}
}
func facebookRegister(withEmail email: String, cellphone: String) {
guard let user = facebookUserStore else {
fatalError("Error linking accounts")
}
register(withUser: user) { (completed) in
if completed {
self.linkAccount(withEmail: email, cellphone: cellphone, completion: { (completion) in
if completion {
self.pushHome()
}
})
}
}
}
func signUp(withUser user: User) {
register(withUser: user) { (_) in
print("registrado")
UserDefaults.Account.set(true, forKey: .isUserLoggedIn)
self.pushHome()
}
}
}
当单击 fbButton 时,该函数通过此 View 内的委托(delegate)执行。
登录查看
//
// LoginView.swift
// TaxiApp
//
// Created by Leonardo Dominguez on 10/2/17.
// Copyright © 2017 Leonardo Dominguez. All rights reserved.
//
import UIKit
class LoginView: BaseView {
var delegate: AuthControllerDelegate?
private let emailField: TAField = {
let pf = TAField(placeHolder: "E-mail", keyboardType: .emailAddress)
return pf
}()
private let passwordField: TAField = {
let pf = TAField(placeHolder: "Password")
pf.isSecureTextEntry = true
return pf
}()
private lazy var loginBtn: TAButton = {
let btn = TAButton(title: "Login")
btn.addTarget(self, action: #selector(handleLogin), for: .touchUpInside)
return btn
}()
private let facebookBtn: TAButton = {
let btn = TAButton()
btn.backgroundColor = UIColor(hexString: "#3b5998")
btn.setAttributedTitle(NSAttributedString(string: "Login with Facebook", attributes: [.foregroundColor: UIColor.lightText, .font: UIFont.init(name: Fonts.mediumFont.rawValue, size: 20)!]), for: .normal)
return btn
}()
private let forgotPassword: UIButton = {
let btn = UIButton()
btn.setAttributedTitle(NSAttributedString(string: "Forgot password", attributes: [.foregroundColor: UIColor.placeholderText, .font: UIFont.init(name: Fonts.mediumFont.rawValue, size: 16)!]), for: .normal)
btn.contentHorizontalAlignment = .right
return btn
}()
private let orView: UIView = {
let container = UIView()
let lbl = UILabel()
lbl.text = "or"
lbl.textColor = .lightText
lbl.font = UIFont(name: Fonts.mediumFont.rawValue, size: 20)
let leftLine = UIView()
let rightLine = UIView()
leftLine.backgroundColor = .lightLine
rightLine.backgroundColor = .lightLine
container.addSubview(rightLine)
container.addSubview(lbl)
container.addSubview(leftLine)
rightLine.centerYAnchor.constraint(equalTo: container.centerYAnchor).isActive = true
_ = rightLine.anchor(top: nil, bottom: nil, right: container.rightAnchor, left: lbl.rightAnchor, topConstant: 0, bottomConstant: 0, rightConstant: 70, leftConstant: 3, widthConstant: 0, heightConstant: 1.0)
_ = lbl.centerInView()
leftLine.centerYAnchor.constraint(equalTo: container.centerYAnchor).isActive = true
_ = leftLine.anchor(top: nil, bottom: nil, right: lbl.leftAnchor, left: container.leftAnchor, topConstant: 0, bottomConstant: 0, rightConstant: 3, leftConstant: 70, widthConstant: 0, heightConstant: 1.0)
return container
}()
override func setupViews() {
setupBtns()
addSubview(emailField)
addSubview(passwordField)
addSubview(forgotPassword)
addSubview(loginBtn)
addSubview(orView)
addSubview(facebookBtn)
_ = emailField.anchor(top: topAnchor, bottom: nil, right: rightAnchor, left: leftAnchor, topConstant: 20, bottomConstant: 0, rightConstant: 0, leftConstant: 0, widthConstant: 0, heightConstant: Theme.fieldHeight)
_ = passwordField.anchorWithMultiplier(top: emailField.bottomAnchor, bottom: nil, right: emailField.rightAnchor, left: emailField.leftAnchor, height: emailField.heightAnchor, width: nil, topConstant: Theme.topPadding, bottomConstant: 0, rightConstant: 0, leftConstant: 0, widthMultiplier: 0, heightMultiplier: 1)
_ = forgotPassword.anchor(top: passwordField.bottomAnchor, bottom: nil, right: emailField.rightAnchor, left: emailField.leftAnchor, topConstant: 5, bottomConstant: 0, rightConstant: 0, leftConstant: 0, widthConstant: 0, heightConstant: 0)
_ = loginBtn.anchorWithMultiplier(top: passwordField.bottomAnchor, bottom: nil, right: emailField.rightAnchor, left: emailField.leftAnchor, height: emailField.heightAnchor, width: nil, topConstant: Theme.topPadding, bottomConstant: 0, rightConstant: 0, leftConstant: 0, widthMultiplier: 0, heightMultiplier: 1)
_ = orView.anchor(top: loginBtn.bottomAnchor, bottom: nil, right: rightAnchor, left: leftAnchor, topConstant: Theme.topPadding / 2, bottomConstant: 0, rightConstant: 0, leftConstant: 0, widthConstant: 0, heightConstant: 10)
_ = facebookBtn.anchorWithMultiplier(top: orView.bottomAnchor, bottom: nil, right: emailField.rightAnchor, left: emailField.leftAnchor, height: emailField.heightAnchor, width: nil, topConstant: Theme.topPadding / 2, bottomConstant: 0, rightConstant: 0, leftConstant: 0, widthMultiplier: 0, heightMultiplier: 1)
}
func setupBtns() {
facebookBtn.addTarget(self, action: #selector(handleFacebookLogin), for: .touchUpInside)
}
@objc func handleFacebookLogin() {
delegate?.facebookAuth()
}
@objc func handleLogin() {
if let email = emailField.text, let password = passwordField.text {
let user = User(email: email, password: password)
delegate?.login(withUser: user)
}
}
}
更新
因此,在很多人尝试整个应用程序之后,我只注意到错误属于 RouterController
,它是嵌入了 AuthController
的 UINavigationController 子类。当我更改 Windows rootviewcontroller 以避免 RouterController
并直接转到 AuthController
时,一切都开始工作。现在我的疑问是,为什么会发生这种情况?我试图弄清楚,这样我就可以修复或在将来的情况下,但我不知道为什么,这是我的代码:
路由器 Controller
import UIKit
class RouterController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// perform(#selector(redirect), with: nil, afterDelay: 0)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
redirect()
}
@objc func redirect() {
if UserDefaults.Account.bool(forKey: .isUserLoggedIn) {
viewControllers = [HomeController()]
} else {
setViewControllers([AuthController()], animated: false)
}
}
}
最佳答案
尝试在主线程上执行闭包中的所有内容,如下所示:
func facebookAuth(){
let loginManager = FBSDKLoginManager()
loginManager.logIn(withReadPermissions: ["email", "public_profile"], from: self) {[weak self] (result, err) in
if err == nil, !(result?.isCancelled)!, let token = result?.token.tokenString {
print("Login successful")
DispatchQueue.main.async {
self?.loginView.isHidden = true
self?.bottomBtn.isHidden = true
self?.slide(toView: .registerView)
}
}
}
}
关于ios - 闭包内的自实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46772867/
IO 设备如何知道属于它的内存中的值在memory mapped IO 中发生了变化? ? 例如,假设内存地址 0 专用于保存 VGA 设备的背景颜色。当我们更改 memory[0] 中的值时,VGA
我目前正在开发一个使用Facebook sdk登录(通过FBLoginView)的iOS应用。 一切正常,除了那些拥有较旧版本的facebook的人。 当他们按下“使用Facebook登录”按钮时,他
假设我有: this - is an - example - with some - dashesNSRange将使用`rangeOfString:@“-”拾取“-”的第一个实例,但是如果我只想要最后
Card.io SDK提供以下详细信息: 卡号,有效期,月份,年份,CVV和邮政编码。 如何从此SDK获取国家名称。 - (void)userDidProvideCreditCardInfo:(Car
iOS 应用程序如何从网络服务下载图片并在安装过程中将它们安装到用户的 iOS 设备上?可能吗? 最佳答案 您无法控制应用在用户设备上的安装,因此无法在安装过程中下载其他数据。 只需在安装后首次启动应
我曾经开发过一款企业版 iOS 产品,我们公司曾将其出售给大型企业,供他们的员工使用。 该应用程序通过 AppStore 提供,企业用户获得了公司特定的配置文件(包含应用程序配置文件)以启用他们有权使
我正在尝试将 Card.io SDK 集成到我的 iOS 应用程序中。我想为 CardIO ui 做一个简单的本地化,如更改取消按钮标题或“在此保留信用卡”提示文本。 我在 github 上找到了这个
我正在使用 CardIOView 和 CardIOViewDelegate 类,没有可以设置为 YES 的 BOOL 来扫描 collectCardholderName。我可以看到它在 CardIOP
我有一个集成了通话工具包的 voip 应用程序。每次我从我的 voip 应用程序调用时,都会在 native 电话应用程序中创建一个新的最近通话记录。我在 voip 应用程序中也有自定义联系人(电话应
iOS 应用程序如何知道应用程序打开时屏幕上是否已经有键盘?应用程序运行后,它可以接收键盘显示/隐藏通知。但是,如果应用程序在分屏模式下作为辅助应用程序打开,而主应用程序已经显示键盘,则辅助应用程序不
我在模拟器中收到以下错误: ImageIO: CGImageReadSessionGetCachedImageBlockData *** CGImageReadSessionGetCachedIm
如 Apple 文档所示,可以通过 EAAccessory Framework 与经过认证的配件(由 Apple 认证)进行通信。但是我有点困惑,因为一些帖子告诉我它也可以通过 CoreBluetoo
尽管现在的调试器已经很不错了,但有时找出应用程序中正在发生的事情的最好方法仍然是古老的 NSLog。当您连接到计算机时,这样做很容易; Xcode 会帮助弹出日志查看器面板,然后就可以了。当您不在办公
在我的 iOS 应用程序中,我定义了一些兴趣点。其中一些有一个 Kontakt.io 信标的名称,它绑定(bind)到一个特定的 PoI(我的意思是通常贴在信标标签上的名称)。现在我想在附近发现信标,
我正在为警报提示创建一个 trigger.io 插件。尝试从警报提示返回数据。这是我的代码: // Prompt + (void)show_prompt:(ForgeTask*)task{
您好,我是 Apple iOS 的新手。我阅读并搜索了很多关于推送通知的文章,但我没有发现任何关于 APNS 从 io4 到 ios 6 的新更新的信息。任何人都可以向我提供 APNS 如何在 ios
UITabBar 的高度似乎在 iOS 7 和 8/9/10/11 之间发生了变化。我发布这个问题是为了让其他人轻松找到答案。 那么:在 iPhone 和 iPad 上的 iOS 8/9/10/11
我想我可以针对不同的 iOS 版本使用不同的 Storyboard。 由于 UI 的差异,我将创建下一个 Storyboard: Main_iPhone.storyboard Main_iPad.st
我正在写一些东西,我将使用设备的 iTunes 库中的一部分音轨来覆盖 2 个视频的组合,例如: AVMutableComposition* mixComposition = [[AVMutableC
我创建了一个简单的 iOS 程序,可以顺利编译并在 iPad 模拟器上运行良好。当我告诉 XCode 4 使用我连接的 iPad 设备时,无法编译相同的程序。问题似乎是当我尝试使用附加的 iPad 时
我是一名优秀的程序员,十分优秀!