Когда утра Смена языка с английского sh На арабский c в это время клавиатура Араби c переворачивается, а когда меняю Изменение арабского c на английский sh Язык в то время английский sh Клавиатура есть Перевернул в устройстве. Так есть ли какое-либо решение для предотвращения клавиатуры при смене языка пользователем?
Логотип изменений моего языка c и снимок экрана ниже:
func changeLanguage() {
var transition: UIView.AnimationOptions = .transitionFlipFromLeft
// let window: UIWindow = ((UIApplication.shared.delegate?.window)!)!
// let navController: UINavigationController = UINavigationController(rootViewController: (self.sb.instantiateViewController(withIdentifier: "MenuViewController")))
// let loginVC = self.sb.instantiateViewController(withIdentifier: "LoginVC") as! LoginVC
// let homeVC = self.sb.instantiateViewController(withIdentifier: "HomeVC") as! HomeVC
// navController.viewControllers.insert(loginVC, at: 0)
// navController.viewControllers.append(homeVC)
if L102Language.currentAppleLanguage() == "en" {
L102Language.setAppleLAnguageTo(lang: "ar")
transition = .transitionFlipFromRight
UIView.appearance().semanticContentAttribute = .forceRightToLeft
} else {
L102Language.setAppleLAnguageTo(lang: "en")
transition = .transitionFlipFromRight
UIView.appearance().semanticContentAttribute = .forceLeftToRight
}
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
// UIApplication.shared.keyWindow?.rootViewController = storyboard.instantiateInitialViewController()
UIApplication.shared.windows[0].rootViewController = storyboard.instantiateInitialViewController()
//L102Localizer.DoTheMagic()
NotificationCenter.default.post(name: Notification.Name("restrat"), object: nil)
// navController.navigationBar.tintColor = UIColor.white
// navController.navigationBar.isTranslucent = true
// navController.navigationBar.barTintColor = UIColor(hex: 0xAF7E32)
// let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
// navigationController?.navigationBar.titleTextAttributes = textAttributes
// navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20.0, weight: .semibold)]
let mainwindow = (UIApplication.shared.delegate?.window!)!
// mainwindow.backgroundColor = UIColor(hue: 0.6477, saturation: 0.6314, brightness: 0.6077, alpha: 0.8)
UIView.transition(with: mainwindow, duration: 0.55001, options: transition, animations: { () -> Void in
}) { (finished) -> Void in
}
}
ниже - расширение текстового поля:
class RoundedTextField: UITextField {
let errorMessage = UILabel()
private func getKeyboardLanguage() -> String? {
if L102Language.currentAppleLanguage() == "en" {
return "en" // here you can choose keyboard any way you need
}else{
return "ar"
}
}
override var textInputMode: UITextInputMode? {
if let language = getKeyboardLanguage() {
for tim in UITextInputMode.activeInputModes {
if tim.primaryLanguage!.contains(language) {
return tim
}
}
}
return super.textInputMode
}
Ниже Смена языка Класс:
//
// Localizer.swift
// Localization102
//
// Created by Moath_Othman on 2/24/16.
// Copyright © 2016 Moath_Othman. All rights reserved.
//
import Foundation
import UIKit
extension UIApplication {
// class func isRTL() -> Bool{
// return UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft
// }
}
class L102Localizer: NSObject {
class func DoTheMagic() {
MethodSwizzleGivenClassName(cls: Bundle.self, originalSelector: #selector(Bundle.localizedString(forKey:value:table:)), overrideSelector: #selector(Bundle.specialLocalizedStringForKey(_:value:table:)))
MethodSwizzleGivenClassName(cls: UIApplication.self, originalSelector: #selector(getter: UIApplication.userInterfaceLayoutDirection), overrideSelector: #selector(getter: UIApplication.cstm_userInterfaceLayoutDirection))
MethodSwizzleGivenClassName(cls: UITextField.self, originalSelector: #selector(UITextField.layoutSubviews), overrideSelector: #selector(UITextField.cstmlayoutSubviews))
MethodSwizzleGivenClassName(cls: UILabel.self, originalSelector: #selector(UILabel.layoutSubviews), overrideSelector: #selector(UILabel.cstmlayoutSubviews))
MethodSwizzleGivenClassName(cls: UIImageView.self, originalSelector: #selector(UIImageView.layoutSubviews), overrideSelector: #selector(UIImageView.cstmlayoutSubviews))
// MethodSwizzleGivenClassName(cls: UIButton.self, originalSelector: #selector(UIButton.layoutSubviews), overrideSelector: #selector(UIButton.cstmlayoutSubviews))
}
}
extension UILabel {
@objc public func cstmlayoutSubviews() {
self.cstmlayoutSubviews()
if self.isKind(of: NSClassFromString("UITextFieldLabel")!) {
return // handle special case with uitextfields
}
if self.tag <= -1 {
if L102Language.currentAppleLanguage() == "ar" {
if self.textAlignment == .right {
return
}
} else {
if self.textAlignment == .left {
return
}
}
}
if self.tag <= -1 {
if L102Language.currentAppleLanguage() == "ar" {
self.textAlignment = .right
} else {
self.textAlignment = .left
}
}
}
}
extension UITextField {
@objc public func cstmlayoutSubviews() {
self.cstmlayoutSubviews()
if self.tag <= 0 {
if L102Language.currentAppleLanguage() == "ar" {
if self.textAlignment == .right { return }
self.textAlignment = .right
} else {
if self.textAlignment == .left { return }
self.textAlignment = .left
}
}
}
}
extension UIImageView {
@objc public func cstmlayoutSubviews() {
self.cstmlayoutSubviews()
if self.tag <= 0 {
if L102Language.currentAppleLanguage() == "ar" {
if self.transform == CGAffineTransform(scaleX: -1, y: 1) { return }
self.transform = CGAffineTransform(scaleX: -1, y: 1)
} else {
if self.transform == CGAffineTransform(scaleX: 1, y: 1) { return }
self.transform = CGAffineTransform(scaleX: 1, y: 1)
}
}
}
}
extension UIButton {
@objc public func cstmlayoutSubviews() {
self.cstmlayoutSubviews()
if self.tag <= 0 {
if L102Language.currentAppleLanguage() == "ar" {
if self.contentHorizontalAlignment == .right { return }
self.contentHorizontalAlignment = .right
} else {
if self.contentHorizontalAlignment == .left { return }
self.contentHorizontalAlignment = .left
}
}
}
}
var numberoftimes = 0
extension UIApplication {
@objc var cstm_userInterfaceLayoutDirection : UIUserInterfaceLayoutDirection {
get {
var direction = UIUserInterfaceLayoutDirection.leftToRight
if L102Language.currentAppleLanguage() == "ar" {
direction = .rightToLeft
}else{
direction = .leftToRight
}
return direction
}
}
}
extension Bundle {
@objc func specialLocalizedStringForKey(_ key: String, value: String?, table tableName: String?) -> String {
if self == Bundle.main {
let currentLanguage = L102Language.currentAppleLanguage()
var bundle = Bundle();
if let _path = Bundle.main.path(forResource: L102Language.currentAppleLanguageFull(), ofType: "lproj") {
bundle = Bundle(path: _path)!
}else
if let _path = Bundle.main.path(forResource: currentLanguage, ofType: "lproj") {
bundle = Bundle(path: _path)!
} else {
let _path = Bundle.main.path(forResource: "Base", ofType: "lproj")!
bundle = Bundle(path: _path)!
}
return (bundle.specialLocalizedStringForKey(key, value: value, table: tableName))
} else {
return (self.specialLocalizedStringForKey(key, value: value, table: tableName))
}
}
}
func disableMethodSwizzling() {
}
/// Exchange the implementation of two methods of the same Class
func MethodSwizzleGivenClassName(cls: AnyClass, originalSelector: Selector, overrideSelector: Selector) {
let origMethod: Method = class_getInstanceMethod(cls, originalSelector)!;
let overrideMethod: Method = class_getInstanceMethod(cls, overrideSelector)!;
if (class_addMethod(cls, originalSelector, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod))) {
class_replaceMethod(cls, overrideSelector, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
} else {
method_exchangeImplementations(origMethod, overrideMethod);
}
}