2017-10-20 16 views
4

我正在使用Swift 2.2 for iOS應用程序。iOS 11 - 成爲第一響應者不打開鍵盤

我有一個.TouchUpInside事件觸發一個UITextField成爲第一響應者的UIButton。

下面是輸入:

self.manualInput = BrandTextField(y: 0, parentWidth: self.view.frame.width) 
    self.manualInput.returnKeyType = .Search 
    self.manualInput.autocorrectionType = .No 

    self.manualInput.hidden = true 
    self.manualInput.text = "" 
    self.manualInput.delegate = self 
    self.manualInput.autocapitalizationType = .AllCharacters 
    self.manualInput.moveX(0) 
    self.manualInput.changeWidth(self.view.frame.width) 
    self.manualInput.layer.cornerRadius = 0 

    self.backgroundView.addSubview(self.manualInput) 

下面的按鈕:

self.keyboardButton = ActionButton(x: Dimensions.xScaleValue(170), y: Dimensions.yScaleValue(495), onTitle: "Enter code", offTitle: "Enter code", onImage: "manual_entry", offImage: "manual_entry", imageOn: true, action: { 
    self.manualInput.becomeFirstResponder() 
    print("Open the input") 
}) 
self.backgroundView.addSubview(self.keyboardButton) 

我也有這兩個觀察員:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyBoardWillShow), name: UIKeyboardDidShowNotification, object: nil) 
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyBoardWillHide), name: UIKeyboardWillHideNotification, object: nil) 


func keyBoardWillShow(notification: NSNotification) { 
    print("Keyboard will show") 
    let frame = (notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue() 

    self.manualInput.moveY(frame.origin.y - self.manualInput.frame.height) 
    self.manualInput.hidden = false 
} 

func keyBoardWillHide(notification: NSNotification) { 
    print("Keyboard will hide") 
    self.manualInput.moveY(0) 
    self.manualInput.hidden = true 
} 

的問題是,當我按下按鈕從iOS 11開始,會變成becomeFirstResponder()行,但不顯示鍵盤。

我這裏奇怪的是,如果我初始化視圖內的輸入,並使其不隱藏,按鈕仍然無法正常工作。除非我點擊輸入,關閉鍵盤然後使用按鈕觸發。

我不知道我是否在iOS 11的設置中缺少某些東西,或者如果我不能再執行此操作?

任何幫助是大規模讚賞。

+2

會發生這種情況的設備或模擬器上? – PoolHallJunkie

+1

嗨,這發生在模擬器和設備上。 – StephenBrown1990

+0

嗨,我有同樣的問題。你找到解決方案嗎? –

回答

相關問題