iOS InputAccessory视图方向错误
我有一个视图,可以旋转,而整个其他应用程序不旋转。 使用视图变换而不是旋转整个viewController完成的旋转。 问题在于,在横向模式下,键盘的inputaccessory视图方向错误-键盘在横向模式下显示正确,而inputaccessory视图显示为纵向: 在纵向方向上,所有外观都正确: 我正在使用扩展构建输入附件视图:iOS InputAccessory视图方向错误,ios,objective-c,swift,iphone,inputaccessoryview,Ios,Objective C,Swift,Iphone,Inputaccessoryview,我有一个视图,可以旋转,而整个其他应用程序不旋转。 使用视图变换而不是旋转整个viewController完成的旋转。 问题在于,在横向模式下,键盘的inputaccessory视图方向错误-键盘在横向模式下显示正确,而inputaccessory视图显示为纵向: 在纵向方向上,所有外观都正确: 我正在使用扩展构建输入附件视图: extension UITextField { static var _doneAccessoryViewButtonCallback = [String:
extension UITextField
{
static var _doneAccessoryViewButtonCallback = [String:()->Void]()
var doneAccessoryViewButtonCallback:(()->Void)? {
get {
let tmpAddress = String(format: "%p", unsafeBitCast(self, to: Int.self))
return UITextField._doneAccessoryViewButtonCallback[tmpAddress]
}
set(newValue) {
let tmpAddress = String(format: "%p", unsafeBitCast(self, to: Int.self))
UITextField._doneAccessoryViewButtonCallback[tmpAddress] = newValue
}
}
@IBInspectable var doneAccessory: Bool{
get{
return self.doneAccessory
}
set (hasDone) {
if hasDone{
addDoneButtonOnKeyboard()
}
}
}
func addDoneButtonOnKeyboard()
{
let view:UIView = UIView()
view.frame = CGRect(x: CGFloat(0), y: CGFloat(0), width: UIScreen.main.bounds.width, height: CGFloat(44))
view.backgroundColor = UIColor.RGB(hexString: "#D1D5DB")
let button: UIButton = self.getButton()
view.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
button.constrainToRightOfSuperView(CGFloat(16))
button.centerVerticallyInSuperView()
self.inputAccessoryView = view
let version = OperatingSystemVersion(majorVersion: 13, minorVersion: 0, patchVersion: 0)
if ProcessInfo.processInfo.isOperatingSystemAtLeast(version) {
view.translatesAutoresizingMaskIntoConstraints = false
view.stretchToBoundsOfSuperView()
} else {
view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
}
}
func isEmpty() -> Bool
{
return self.text == nil || self.text!.count == 0
}
// MARK: -
// MARK: - PRIVATES
private func getButton() -> UIButton
{
let button = UIButton(type: .custom)
let attString:NSMutableAttributedString = NSMutableAttributedString(string: "Done")
attString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.RGB(0xed, g: 0x3c, b: 00), range: NSRange(location: 0, length: attString.string.length))
attString.addAttribute(NSAttributedString.Key.font, value: UIFont(name: "Avenir-Book", size: 17)!, range: NSRange(location: 0, length: attString.string.length))
button.setAttributedTitle(attString, for: .normal)
button.addTarget(self, action: #selector(doneButtonAction), for: .touchUpInside)
return button
}
@objc func doneButtonAction()
{
self.resignFirstResponder()
self.doneAccessoryViewButtonCallback?()
}
}
这个问题的解决方案是什么?我不确定这个解决方案,因为我们做了很多重构,但我认为它与顶部的某个窗口有关,而不是我显示键盘的窗口,而是纵向的。