How to display UIView over keyboard in iOS

pavel_s picture pavel_s · Sep 4, 2015 · Viewed 9.7k times · Source

I want to create a simple view over keyboard, when users tap "Attach" button in inputAccessoryView. Something like this:

enter image description here

Is there an easy way to do it? Or i should create my custom keyboard?

Answer

Midhun MP picture Midhun MP · Sep 4, 2015

You can add that new subview to your application window.

func attach(sender : UIButton)
{
    // Calculate and replace the frame according to your keyboard frame
    var customView = UIView(frame: CGRect(x: 0, y: self.view.frame.size.height-300, width: self.view.frame.size.width, height: 300))
    customView.backgroundColor = UIColor.redColor()
    customView.layer.zPosition = CGFloat(MAXFLOAT)
    var windowCount = UIApplication.sharedApplication().windows.count
    UIApplication.sharedApplication().windows[windowCount-1].addSubview(customView);
}