         super.init(frame: frame)
         
         self.clipsToBounds = false
+        self.keyView.setTranslatesAutoresizingMaskIntoConstraints(false)
         self.addSubview(self.keyView)
+        
+        self.addConstraint(NSLayoutConstraint(item: self, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: self.keyView, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: 0))
+        self.addConstraint(NSLayoutConstraint(item: self, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: self.keyView, attribute: NSLayoutAttribute.Height, multiplier: 1, constant: 0))
+        self.addConstraint(NSLayoutConstraint(item: self, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self.keyView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
+        self.addConstraint(NSLayoutConstraint(item: self, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self.keyView, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 0))
         
         self.ambiguityTimer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: "timerLoop", userInfo: nil, repeats: true)
         

            self.popupDirection = Direction.Up
            self.setupPopupConstraints(self.popupDirection)
            self.configurePopup(self.popupDirection)
            
//            if self.popup!.frame.height < 20 {
//            NSLog("popup frame is \(NSStringFromCGRect(self.popup!.frame))")
            
            var popupPosition = self.superview.convertPoint(self.popup!.frame.origin, fromView: self)
            popupPosition.y = popupPosition.y - self.popup!.frame.height
            NSLog("popup positio is \(NSStringFromCGPoint(popupPosition))")
            
            if popupPosition.y < 13 {
                if self.frame.origin.x < self.superview.bounds.width/2 {
                    self.popupDirection = Direction.Right
                }
                else {
                    self.popupDirection = Direction.Left
                }
                
                self.setupPopupConstraints(self.popupDirection)
                self.configurePopup(self.popupDirection)
                
                super.layoutSubviews()
                
                var popupPosition = self.superview.convertPoint(self.popup!.frame.origin, fromView: self)
                popupPosition.y = popupPosition.y - self.popup!.frame.height
                NSLog("popup positio is \(NSStringFromCGPoint(popupPosition))")
            }
        }
        

    }
    
    func redrawText() {
//        self.keyView.frame = self.bounds
//        self.button.frame = self.bounds
//        
//        self.button.setTitle(self.text, forState: UIControlState.Normal)
        
        self.keyView.text = (self.text ? self.text : "")
    }
    
