Reputation: 68
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
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)
}
Upvotes: 0
Views: 904
Reputation: 16327
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; it really depends on the effect you want to achieve. Note the methods are on UIScrollView which is the parent class of 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. This will automatically push the collectionview up so you don't have to mess withthe constraints.
Upvotes: 1