ios - 如何在 iOS 中通过键盘显示 UIView

标签 ios swift uiview uikeyboard

当用户点击 inputAccessoryView 中的“附加”按钮时,我想通过键盘创建一个简单的 View 。 像这样:

enter image description here

有什么简单的方法吗?或者我应该创建我的自定义键盘?

最佳答案

您可以将新的 subview 添加到您的应用程序窗口。

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);
}

关于ios - 如何在 iOS 中通过键盘显示 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32391704/

相关文章:

ios - 如何在 Swift 中安排通知

objective-c - 如何将字符串作为 UIButton 的标签传递

ios - 无法识别的选择器作为按钮发送到 Collection View 单元格的实例,该按钮将数据从按钮发送到另一个 View Controller

ios - 动态创建 NSMutableArray,并在对象上使用带参数的选择器

ios - UITextField 添加到 UIView 时不响应触摸事件

ios - 可以填充选择器 View 但不能从中获取数据

ios - 在 iOS 上实现按钮网格

ios - Swift 3 - 具有静态方法的协议(protocol)、具有泛型类型的实例方法、可选 '.Type' 参数

swift - 将 CoreML 与 React Native 结合使用

ios - 在 UIBarButtonItem 的 customView 字段中更新 UIView