2015-01-30 15 views
6

Per replicare:iOS 8 - Tastiera cambia colore se si preme il tasto Home sul iPad e tornare in

  1. Creare un vuoto di progetto single-view
  2. Trascinare un TextField sulla tela
  3. Set TextField keyboardAppearance a dark
  4. eseguire l'applicazione su iPad (dispositivo o simulatore)
  5. Toccare il TextField per far apparire la tastiera (è buio)
  6. Premere Home, quindi tornare nell'app
  7. Si noti che la tastiera cambia colore (in bianco).

Presumibilmente il colore della tastiera cambia in base allo sfondo. Tuttavia in questo caso alcuni dei tasti rimangono scuri, quindi questo sembra un bug in iOS (vedi screenshot allegato).

Qualcuno vuole fare luce su questo? Stiamo usando una soluzione alternativa che consiste nel nascondere la tastiera e nella sua ri-visualizzazione, ma non è l'ideale.

enter image description here

+0

Invece di nascondere e mostrare la tastiera di nuovo, provare '[textField reloadInputViews]' su 'viewWillAppear' – Fennelouski

risposta

0

Questo codice può chiudere la tastiera quando si preme pulsante Home e riportarlo quando l'applicazione ripartenza. È necessario impostare UITextFields delegato al controller della vista:

class ViewController: UIViewController, UITextFieldDelegate { 

private var _textField: UITextField! 
private var _isFirstResponder: Bool! 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    NSNotificationCenter.defaultCenter().addObserver(self, 
     selector: "didBecomeActiveNotification:", name: UIApplicationDidBecomeActiveNotification, object: nil) 

    NSNotificationCenter.defaultCenter().addObserver(self, 
     selector: "willResignActiveNotification:", name: UIApplicationWillResignActiveNotification, object: nil) 

} 

deinit { 
    NSNotificationCenter.defaultCenter().removeObserver(self) 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

func didBecomeActiveNotification(nofication: NSNotification) { 
    if _isFirstResponder? == true { 
     _textField?.becomeFirstResponder() 
    } 
} 

func willResignActiveNotification(nofication: NSNotification) { 
    if _textField?.isFirstResponder() == true { 
     _isFirstResponder = true 
     _textField?.resignFirstResponder() 
    } else { 
     _isFirstResponder = false 
    } 
} 

func textFieldShouldBeginEditing(textField: UITextField) -> Bool { 
    _textField = textField 
    return true 
} 

} 
Problemi correlati