[英]Move scroll view when cell hidden by the DatePicker
I have a collection view in which if I click an element a date picker shows up. 我有一个集合视图,如果单击某个元素,则会显示一个日期选择器。 Now, I have been trying to scroll my view up if it gets hidden by the date picker but with no luck. 现在,我一直在尝试向上滚动我的视图(如果它被日期选择器隐藏但没有运气)。 Any help would be appreciated. 任何帮助,将不胜感激。 This is my code for creating a DatePicker with a toolbar 这是我用工具栏创建DatePicker的代码
func createUIPickerView(){
//:Creating a date picker and the toolbar
picker = UIDatePicker(frame: CGRect(x: 0, y: self.view.frame.size.height-216, width: self.view.frame.size.width, height: 216))
picker.backgroundColor = UIColor.white
picker.datePickerMode = .time
toolBar = UIToolbar(frame: CGRect(x: 0, y: self.view.frame.size.height - 50 - 216, width: self.view.frame.size.width, height: 50))
toolBar.barStyle = .default
toolBar.barTintColor = UIColor.white
toolBar.isTranslucent = true
let doneButton = UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(CalenderVC.doneClick))
let spaceButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let cancelButton = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(CalenderVC.cancelClick))
toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false)
toolBar.isUserInteractionEnabled = true
self.view.addSubview(toolBar)
self.view.addSubview(picker)
}
I can't see code for your collection view, but either you: 我看不到您的收藏夹视图的代码,但是您要么:
I usually vote for 1, but possibly a combination of 2 and 3, or maybe just 2 if you know you don't need the inset; 我通常投1票,但也可能投2票和3票,或者如果您知道不需要插入票,则投2票。 it really depends on the effect you want to achieve. 这实际上取决于您要实现的效果。 Note the methods are on UIScrollView which is the parent class of UICollectionView. 注意,方法在UIScrollView上,UIScrollView是UICollectionView的父类。
EDIT: Oh there is one more you can do since you are not using the datePicker as an inputView to a textField: embed your collection view in a stackview, then add the picker to the stackview's arranged subviews. 编辑:哦,您还可以做更多的事情,因为您没有将datePicker用作textField的inputView:将您的集合视图嵌入stackview中,然后将选择器添加到stackview的已安排子视图中。 This will automatically push the collectionview up so you don't have to mess withthe constraints. 这将自动将collectionview向上推,因此您不必弄乱约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.