小编sri*_*ran的帖子

如何以编程方式在iOS中获得较高的导航栏

keyboardwillshown当键盘隐藏时,我必须将视图向上移动到正常位置

实际上,我在viewdidload方法上使用了以下代码:

override func viewDidLoad() { 

    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil) 

}
Run Code Online (Sandbox Code Playgroud)

这是我用来上下移动的方法

func keyboardWillShow(notification:NSNotification){ 

    print("keyboardwillshow")
    let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue()

    self.view.frame = CGRectMake(0.0, -keyboardSize!.size.height + (self.navigationController?.navigationBar.frame.size.height)! + 20 , self.view.frame.size.width, self.view.frame.size.height )  

}

func keyboardWillHide(notification:NSNotification){

    self.view.frame = CGRectMake(0.0,(self.navigationController?.navigationBar.frame.size.height)!, self.view.frame.size.width, self.view.frame.size.height)
//  self.view.frame.origin.y += 350

}
Run Code Online (Sandbox Code Playgroud)

当我运行该程序时,它将显示一个运行时错误,

意外发现展开时发现零

请帮我解决这个问题。

xcode objective-c uinavigationbar ios swift

5
推荐指数
2
解决办法
6809
查看次数

标签 统计

ios ×1

objective-c ×1

swift ×1

uinavigationbar ×1

xcode ×1