I want to create an attachment view, which is placed under the appearance of an auxiliary input, on top of the keyboard, for example, in a Skype or Viber application:

I already asked such a question here , but the proposed solution for this question was not so elegant, because when I drag my scroll view up, I want the UIView application to move down using the keyboard (I use UIScrollViewKeyboardDismissModeInteractive).
So, I create a function that detects the view where the keyboard and my custom accessory view are located:
func findKeyboardView() -> UIView? { var result: UIView? = nil let windows = UIApplication.sharedApplication().windows for window in windows { if window.description.hasPrefix("<UITextEffectsWindow") { for subview in window.subviews { if subview.description.hasPrefix("<UIInputSetContainerView") { for sv in subview.subviews { if sv.description.hasPrefix("<UIInputSetHostView") { result = sv as? UIView break } } break } } break } } return result }

And after that I add my custom UIView and create a few restrictions:
func createAttachView() { attach = MessageChatAttachmentsView(frame: CGRectZero) let newView = findKeyboardView() newView!.addSubview(attach!) newView!.addConstraint(NSLayoutConstraint(item: accessoryView, attribute: .Bottom, relatedBy: .Equal, toItem: attach!, attribute: .Top, multiplier: 1.0, constant: 0.0)) attach!.addConstraint(NSLayoutConstraint(item: attach!, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 260)) attach!.addConstraint(NSLayoutConstraint(item: attach!, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 320)) }
Create a custom UIView as an auxiliary input and above the keyboard, and it moves as you scroll up. But when I want to press a button, I press a key on the keyboard.

So, how can I move this view to the top hierarchy of the view in UIInputSetHostView?