2016-06-06 10 views
0

Ich habe den folgenden benutzerdefinierten Tastencode:IOS-Tastatur wird nicht als Show in kleinen Stück Code hinzufügen

override func viewDidLoad() { 
    super.viewDidLoad() 

    //As soon as I add in this code the keyboard will not showup and instead 
    //selecting this keyboard just reverts back to the normal keyboard 
    let testOne = UIButton() 
    testOne.backgroundColor = UIColor.blackColor() 
    testOne.translatesAutoresizingMaskIntoConstraints = false 
    testOne.widthAnchor.constraintEqualToAnchor(self.view.widthAnchor, multiplier: 0.5).active = true 
    testOne.heightAnchor.constraintEqualToAnchor(self.view.heightAnchor, multiplier: 0.5).active = true 
    testOne.leftAnchor.constraintEqualToAnchor(self.view.leftAnchor).active = true 
    testOne.topAnchor.constraintEqualToAnchor(self.view.topAnchor).active = true 
    self.view.addSubview(testOne) 


    // Default system generated code that creates a "next keyboard" button. 
    self.nextKeyboardButton = UIButton(type: .System) 

    self.nextKeyboardButton.setTitle(NSLocalizedString("Next Keyboard", comment: "Title for 'Next Keyboard' button"), forState: .Normal) 
    self.nextKeyboardButton.sizeToFit() 
    self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = false 

    self.nextKeyboardButton.addTarget(self, action: "advanceToNextInputMode", forControlEvents: .TouchUpInside) 

    self.view.addSubview(self.nextKeyboardButton) 

    let nextKeyboardButtonLeftSideConstraint = NSLayoutConstraint(item: self.nextKeyboardButton, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant: 0.0) 
    let nextKeyboardButtonBottomConstraint = NSLayoutConstraint(item: self.nextKeyboardButton, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1.0, constant: 0.0) 
    self.view.addConstraints([nextKeyboardButtonLeftSideConstraint, nextKeyboardButtonBottomConstraint]) 


} 

Aus irgendeinem Grunde Zugabe in meiner testOneUIButton bewirkt, dass die Tastatur nicht (statt ShowUp, wenn ich es wählen die Standardtastatur erscheint einfach wieder).

Ist meine Taste, die meine benutzerdefinierte Tastatur zum Absturz bringt?

UPDATE ONE: Sobald ich die Zeile testOne.widthAnchor.constraintEqualToAnchor(...).active = true unkommentiert hat, fing der Fehler an, zu geschehen.

Kann ich in der viewDidLoad() Methode keine benutzerdefinierten Einschränkungen erstellen?

Antwort

0

Setzen Sie die Zeile: self.view.addSubview(testOne) , bevor Sie eine der Bedingungen ändern.