pav*_*l_s 10 uiview uikeyboard ios swift
当用户点击inputAccessoryView中的"附加"按钮时,我想在键盘上创建一个简单的视图.像这样的东西:
有一个简单的方法吗?或者我应该创建我的自定义键盘?
Mid*_* MP 14
您可以将新的子视图添加到应用程序窗口.
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);
}
Run Code Online (Sandbox Code Playgroud)
斯威夫特 4 版本:
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)
Run Code Online (Sandbox Code Playgroud)
诀窍是将customView作为顶部子视图添加到UIWindow持有键盘的 中 - 它恰好是UIApplication.shared.windows.
迅捷4.0
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(MAXFLOAT)
let windowCount = UIApplication.shared.windows.count
UIApplication.shared.windows[windowCount-1].addSubview(customView)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7011 次 |
| 最近记录: |