How to display UIView over keyboard in iOS

前端 未结 7 949
醉话见心
醉话见心 2020-12-05 20:04

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

Is there an easy way to do it? O

7条回答
  •  长情又很酷
    2020-12-05 20:24

    Swift 4 version:

    let customView = UIView(frame: CGRect(x: 0, y: self.view.frame.size.height - 300, width: self.view.frame.size.width, height: 300))
    customView.backgroundColor = UIColor.red
    customView.layer.zPosition = CGFloat(Float.greatestFiniteMagnitude)
    UIApplication.shared.windows.last?.addSubview(customView)
    

    The trick is to add the customView as a top subview to the UIWindow that holds the keyboard - and it happens to be the last window in UIApplication.shared.windows.

提交回复
热议问题