从XIB文件加载时,Swift中的iOS键盘太宽太高
我正在使用Swift(iOS8.3SDK的XCode 6)构建一个键盘,当我加载xib时,键盘大约有1000像素太宽太高了。在freeform xib文件中,我将所有键都放在UIView中,并将UIView约束设置为superview top、bottom、left和right 正如你所看到的,结果令人恼火。这是我的密码:从XIB文件加载时,Swift中的iOS键盘太宽太高,ios,iphone,xcode,swift,xib,Ios,Iphone,Xcode,Swift,Xib,我正在使用Swift(iOS8.3SDK的XCode 6)构建一个键盘,当我加载xib时,键盘大约有1000像素太宽太高了。在freeform xib文件中,我将所有键都放在UIView中,并将UIView约束设置为superview top、bottom、left和right 正如你所看到的,结果令人恼火。这是我的密码: import UIKit class KeyboardViewController: UIInputViewController { var BlurBoardView
import UIKit
class KeyboardViewController: UIInputViewController {
var BlurBoardView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
loadInterface()
}
func loadInterface() {
//load the nib file
var blurboardNib = UINib(nibName: "BlurBoardView", bundle: nil)
// initiate the view
BlurBoardView = blurboardNib.instantiateWithOwner(self, options: nil)[0] as! UIView
// add the interface to the main view
view.addSubview(BlurBoardView)
// copy the background color
view.backgroundColor = BlurBoardView.backgroundColor
let blur = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.Light))
blur.frame = view.frame
view.addSubview(blur)
}
@IBAction func didTapButton(sender: AnyObject?) {
let button = sender as! UIButton
let title = button.titleForState(.Normal)
var proxy = textDocumentProxy as! UITextDocumentProxy
switch title as String!{
case "<" :
proxy.deleteBackward()
case "RETURN" :
proxy.insertText("\n")
case " " :
proxy.insertText(" ")
case "CHG" :
self.advanceToNextInputMode()
default :
proxy.insertText(title!)
}
}
/*
override func textWillChange(textInput: UITextInput) {
// The app is about to change the document's contents. Perform any preparation here.
}
override func textDidChange(textInput: UITextInput) {
// The app has just changed the document's contents, the document context has been updated.
var textColor: UIColor
var proxy = self.textDocumentProxy as! UITextDocumentProxy
if proxy.keyboardAppearance == UIKeyboardAppearance.Dark {
textColor = UIColor.whiteColor()
} else {
textColor = UIColor.blackColor()
}
//self.nextKeyboardButton.setTitleColor(textColor, forState: .Normal)
}
*/
}
导入UIKit
类KeyboardViewController:UIInputViewController{
var BlurBoardView:UIView!
重写func viewDidLoad(){
super.viewDidLoad()
loadInterface()
}
func loadInterface(){
//加载nib文件
var blurboardNib=UINib(nibName:“BlurBoardView”,bundle:nil)
//启动视图
BlurBoardView=blurboardNib.InstanceWithOwner(self,选项:nil)[0]作为!UIView
//将界面添加到主视图
view.addSubview(BlurBoardView)
//复制背景色
view.backgroundColor=BlurBoardView.backgroundColor
让blur=UIVisualEffectView(效果:UIBlurEffect(样式:UIBlurEffectStyle.Light))
blur.frame=view.frame
视图。添加子视图(模糊)
}
@iAction func didTapButton(发件人:AnyObject?){
let button=发送方为!UIButton
让title=button.titleForState(.Normal)
var proxy=textDocumentProxy as!UITextDocumentProxy
将标题切换为字符串{
案例“看起来像是在使用自动布局,而不是在视图和BlurBoardView之间设置约束
调用ViewDidLoad时,视图没有正确的框架。只有在调用viewDidLayoutSubviews时,视图才具有正确的框架
因此,在ViewDidLoad中设置视图和BlurBoardView之间的约束。或者在viewDidLayoutSubview中放置BlurBoardView.frame=您希望的框架
对你的blurView来说也是一样的!将BlurBoardView.frame=view.frame
放入viewDidLayoutSubviews中成功了!谢谢。