gpt4 book ai didi

ios - 自动布局多个 UITextviews 和标签 - Swift

转载 作者:行者123 更新时间:2023-11-28 08:48:10 25 4
gpt4 key购买 nike

我正在为学生注册创建一个 iOS 应用程序。我的问题是我无法让自动布局适用于所有设备。我想布局我的界面,每个标签和 TextView 之间的间距均匀。任何帮助都感激不尽。 storyboard capture here

@IBOutlet weak var bottomconst: NSLayoutConstraint!




override func viewDidLoad() {
super.viewDidLoad()







NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil);
//
// NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyBoardDidShow:", name: UIKeyboardDidShowNotification, object: nil)



NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWasShown:", name: UIKeyboardWillShowNotification, object: nil)

// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/



func keyboardWasShown(notification: NSNotification) {
let info = notification.userInfo!
let keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()

//bottomspace = self.bottomconst.constant;

UIView.animateWithDuration(0.1, animations: { () -> Void in
self.view.layoutIfNeeded()

self.bottomconst.constant = keyboardFrame.size.height + 20

})
}






func keyboardWillHide(sender: NSNotification) {
if let keyboardSize = (sender.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
self.bottomconst?.constant -= keyboardSize.height
}
}

最佳答案

我附上了一张带有约束的截图,这样你就可以基本了解如何设置适当的约束,但在你的情况下,如果你的字段数量增加,那么你的所有字段都会自动出现在 scrollView 中,最好使用 TableView 它在较小的设备中很容易看到,但是如果您不想使用 tableview 并且字段数量较少,则可以查看此屏幕截图。 enter image description here

关于ios - 自动布局多个 UITextviews 和标签 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34734937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com