我是设计新系统的团队的一部分。我们选择Angular作为我们的前端框架,并开始研究它的实现。
现在我遇到了障碍。我的想法是在html上创建输入,并基于Angular中的对象填充,隐藏或标记它们,我想为每个输入创建单个对象,例如:
import UIKit
import Foundation
extension UIView {
func currentFirstResponder() -> UIResponder? {
if self.isFirstResponder {
return self
}
for view in self.subviews {
if let responder = view.currentFirstResponder() {
return responder
}
}
return nil
}
}
extension Notification.Name{
static let showKeyboard = Notification.Name("showKeyboard")
}
class KeyboardSlider: NSObject {
// variables to hold and process information from the view using this class
weak var view: UIView?
var searchBarTopTags:SearchBarTopTagsViewController?
var amountToShiftBy:CGFloat!
var originalFrame:CGRect!
@objc func keyboardWillShow(notification: NSNotification) {
self.originalFrame = self.searchBarTopTags?.myView.frame
self.amountToShiftBy = (self.searchBarTopTags?.view.frame.maxY)! - self.getKeyboardHeight(notification as! Notification) - (self.searchBarTopTags?.myView.frame.height)!
self.amountToShiftBy = (searchBarTopTags?.view.bounds.height)! - self.getKeyboardHeight(notification as! Notification) - (searchBarTopTags?.myView.bounds.height)!
self.searchBarTopTags?.myView.bottomAnchor.constraint(equalTo: (self.searchBarTopTags?.view.bottomAnchor)!, constant: -self.amountToShiftBy).isActive = true
UIView.animate(withDuration: 0, animations: {
self.view?.layoutIfNeeded()
self.searchBarTopTags?.view.layoutIfNeeded()
self.searchBarTopTags?.myView.layoutIfNeeded() })
}
@objc func keyboardWillHide(notification:NSNotification){
self.searchBarTopTags?.myView.bottomAnchor.constraint(equalTo: (self.searchBarTopTags?.view.bottomAnchor)!, constant: 0).isActive = true
UIView.animate(withDuration: 0, animations: {
self.view?.layoutIfNeeded()
self.searchBarTopTags?.view.layoutIfNeeded()
self.searchBarTopTags?.myView.layoutIfNeeded()
})
}
func getKeyboardHeight(_ notification:Notification) -> CGFloat {
// get exact height of keyboard on all devices and convert to float value to return for use
let userInfo = notification.userInfo
let keyboardSize = userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue
return keyboardSize.cgRectValue.height
}
func subscribeToKeyboardNotifications(view: UIView) {
// assigning view to class' counterpart
self.view = view
// when UIKeyboardWillShow do keyboardWillShow function
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: .UIKeyboardWillShow, object: nil)
}
func subscribeToKeyboardNotifications(view: UIView, seachBarTopTagsVC:SearchBarTopTagsViewController? = nil) {
// assigning view to class' counterpart
self.view = view
self.searchBarTopTags = seachBarTopTagsVC
// when UIKeyboardWillShow do keyboardWillShow function
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: .UIKeyboardWillHide, object: nil)
}
func unsubscribeFromKeyboardNotifications() {
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillHide, object: nil)
}
}
另一个想法是,从以下开始为该对象的每个部分创建对象:
inputPhone = {
'label': 'Mobile phone',
'placeholder': '987 333 987',
'validate': {
'required': true
},
'options': {
'required': true,
'hidden': false
}
};
因此,我想让它更多地了解是否有某种东西与我在某处错过的标准接近。