我正在使用自定义键盘,并希望在界面中添加一些UIImageViews。我可以加载.Xib精细,如下所示,但是当我尝试在主视图中创建UIImage时,它会导致崩溃。你知道为什么会这样吗?
import UIKit
class KeyboardViewController: UIInputViewController {
override func updateViewConstraints() {
super.updateViewConstraints()
}
override func viewDidLoad() {
super.viewDidLoad()
let myView = NSBundle.mainBundle().loadNibNamed("KeyboardView", owner: nil, options: nil)[0] as UIView
self.view.addSubview(myView)
let image = UIImage(named: "grid.png")
let imageSize = CGSize(width: 216, height: 216)
var gridImageView = UIImageView(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: imageSize))
gridImageView.image = image
//tried this- Crashes
self.addSubview(gridImageView)
//also tried this- Crashes
self.view.insertSubview(view: gridImageView, aboveSubview: myView)
}
如果我手动将ImageView添加到.XIB,它也会崩溃。我觉得UIInputViewController不会让你使用图像视图,即使文档表明它是可能的。我通常是这些东西的白痴,所以可能误解了文档: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIInputViewController_Class/index.html#//apple_ref/occ/instp/UIInputViewController/inputView