Ios 快速多底单
我已经使用其他人在这里提供的教程实现了一个底部工作表。一切都进行得很顺利,但是我想实现一个位于该底部工作表之上的底部工作表,以及可能位于前一个底部工作表之上的多个其他底部工作表。我想实现这一点,就像ios10地图的底图一样。i、 e.如果一张底纸叠在另一张底纸上,您只需按左上角的“x”即可将其关闭 这是我目前的代码: 在我的地图视图控制器中,我添加了:Ios 快速多底单,ios,swift,swift3,bottom-sheet,Ios,Swift,Swift3,Bottom Sheet,我已经使用其他人在这里提供的教程实现了一个底部工作表。一切都进行得很顺利,但是我想实现一个位于该底部工作表之上的底部工作表,以及可能位于前一个底部工作表之上的多个其他底部工作表。我想实现这一点,就像ios10地图的底图一样。i、 e.如果一张底纸叠在另一张底纸上,您只需按左上角的“x”即可将其关闭 这是我目前的代码: 在我的地图视图控制器中,我添加了: func addBottomSheetView() { // 1- Init bottomSheetVC let bottomS
func addBottomSheetView() {
// 1- Init bottomSheetVC
let bottomSheetVC = BottomSheetViewController()
// 2- Add bottomSheetVC as a child view
self.addChildViewController(bottomSheetVC)
self.view.addSubview(bottomSheetVC.view)
bottomSheetVC.didMoveToParentViewController(self)
// 3- Adjust bottomSheet frame and initial position.
let height = view.frame.height
let width = view.frame.width
bottomSheetVC.view.frame = CGRectMake(0, self.view.frame.maxY, width, height)
}
override func viewDidLoad() {
super.viewDidLoad()
let gesture = UIPanGestureRecognizer.init(target: self, action: #selector(BottomSheetViewController.panGesture))
view.addGestureRecognizer(gesture)
}
func panGesture(recognizer: UIPanGestureRecognizer) {
let translation = recognizer.translationInView(self.view)
let y = self.view.frame.minY
self.view.frame = CGRectMake(0, y + translation.y, view.frame.width, view.frame.height)
recognizer.setTranslation(CGPointZero, inView: self.view)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
UIView.animateWithDuration(0.3) { [weak self] in
let frame = self?.view.frame
let yComponent = UIScreen.mainScreen().bounds.height - 200
self?.view.frame = CGRectMake(0, yComponent, frame!.width, frame!.height)
}
}
并在ViewDidDisplay方法中调用它:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
addBottomSheetView()
}
在我的底部板材控制器中,我添加了:
func addBottomSheetView() {
// 1- Init bottomSheetVC
let bottomSheetVC = BottomSheetViewController()
// 2- Add bottomSheetVC as a child view
self.addChildViewController(bottomSheetVC)
self.view.addSubview(bottomSheetVC.view)
bottomSheetVC.didMoveToParentViewController(self)
// 3- Adjust bottomSheet frame and initial position.
let height = view.frame.height
let width = view.frame.width
bottomSheetVC.view.frame = CGRectMake(0, self.view.frame.maxY, width, height)
}
override func viewDidLoad() {
super.viewDidLoad()
let gesture = UIPanGestureRecognizer.init(target: self, action: #selector(BottomSheetViewController.panGesture))
view.addGestureRecognizer(gesture)
}
func panGesture(recognizer: UIPanGestureRecognizer) {
let translation = recognizer.translationInView(self.view)
let y = self.view.frame.minY
self.view.frame = CGRectMake(0, y + translation.y, view.frame.width, view.frame.height)
recognizer.setTranslation(CGPointZero, inView: self.view)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
UIView.animateWithDuration(0.3) { [weak self] in
let frame = self?.view.frame
let yComponent = UIScreen.mainScreen().bounds.height - 200
self?.view.frame = CGRectMake(0, yComponent, frame!.width, frame!.height)
}
}
最初,我想在新的底部工作表中添加子视图,但是这不起作用。是否应将子视图添加到原始地图视图控制器?添加新底部图纸的按钮位于现有底部图纸中。我想听听你的建议。谢谢