我使用此代码将第一个响应者从一个textField更改为另一个。每个文本字段标记=行+ 100 像第一个textField(第二行)的标签= 101 代码有效:
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.textColor = UIColor.darkTextColor()
let nextTag = textField.tag + 1;
// Try to find next responder
let cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: nextTag-100, inSection: 0))
if(cell == nil)
{
return false
}
let nextResponder = cell!.viewWithTag(nextTag) as UIResponder!
self.view.frame.origin.y = 0
if (nextResponder != nil){
// Found next responder, so set it.
nextResponder?.becomeFirstResponder()
}
else
{
// Not found, so remove keyboard
textField.resignFirstResponder()
}
return false // We do not want UITextField to insert line-breaks.
}
要更改导航栏,请使用以下代码:
func setNavigationBar()
{
self.edgesForExtendedLayout = UIRectEdge.Bottom
self.extendedLayoutIncludesOpaqueBars = false
self.automaticallyAdjustsScrollViewInsets = true
self.navigationController?.navigationBarHidden = false
self.navigationController?.navigationBar.backgroundColor = UIColor.whiteColor()
self.navigationController?.navigationBar.setBackgroundImage(UIImage.fromColor(.whiteColor()), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.view.backgroundColor = UIColor.whiteColor()
self.navigationController?.navigationBar.translucent = true
self.navigationItem.setHidesBackButton(true, animated: false)
self.navigationItem.title = NSLocalizedString("REGISTRATION_TITLE", comment: "")
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "cross_exit"), style:UIBarButtonItemStyle.Plain , target: self, action: "getBackToAuth")
self.navigationController?.navigationBar.tintColor = self.specificGrayColor
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.blackColor(),NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 17)!]
}
但是
self.edgesForExtendedLayout = UIRectEdge.Bottom
效果在返回后消失......
before I tap next After I tap done when filled in last textField
答案 0 :(得分:0)
这可能是由 IQKeyboardSwift 库引起的。 你可以试试
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
IQKeyboardManager.shared.enable = false
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
IQKeyboardManager.shared.enable = true
}
希望能帮到你。