[英]Keyboard appears twice when UITextField becomes first responder after custom segue performed
所以問題是:當我在源代碼視圖上按一個按鈕時,將執行自定義序列。
這是代碼(漂亮的標准):
class FirstCustomSugue: UIStoryboardSegue {
override func perform() {
let initalView = self.source.view as UIView?
let destinationView = self.destination.view as UIView?
let screenHeight = UIScreen.main.bounds.size.height
let screenWidth = UIScreen.main.bounds.size.width
initalView?.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight)
destinationView?.frame = CGRect(x: screenWidth, y: 0, width: screenWidth, height: screenHeight)
let appWindow = UIApplication.shared.keyWindow
appWindow?.insertSubview(destinationView!, aboveSubview: initalView!)
UIView.animate(withDuration: 0.4, animations: {
// Left/Right
initalView?.frame = (initalView?.frame.offsetBy(dx: -screenWidth, dy: 0))!
destinationView?.frame = (destinationView?.frame.offsetBy(dx: -screenWidth, dy: 0))!
}) { (Bool) in
self.source.present(self.destination, animated: false, completion: nil)
}
}
}
我在viewDidiAppear
調用myTextField.becomeFirstResponder()
(包括對super的調用)。
當我將模擬器的“慢動畫”設置為“開”時,我可以清楚地看到鍵盤首先出現在動畫旁邊,動畫完成后它會重新出現。
我提供了一個示例-segue,因為當我切換到標准segue時,沒有這樣的問題。 如果您需要任何其他代碼示例,我將更新帖子。
使用自定義序列,因為我不在過渡視圖之間使用navigationController
,因此默認模態序列不能選擇。
我的猜測是viewDidAppear
被調用了兩次,因為即使我在viewWillAppear
或viewDidLoad
中將myTextField.isUserInteractionEnabled = false
和myTextField.isEnabled = false
為(在兩種方法中的超級方法之前或之后),然后在調用后立即在viewDidAppear
中將它們設置為true超級的結果是一樣的。
提前TNX!
將segue的表演更改為以下內容:
let sourceViewController = self.source
let destinationViewController = self.destination
let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionMoveIn
transition.subtype = kCATransitionFromRight
let appWindow = UIApplication.shared.keyWindow
appWindow?.layer.add(transition, forKey: kCATransition)
sourceViewController.present(destinationViewController, animated: false, completion: nil)ere
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.