OfTheWolf / UBottomSheet

iPhone Maps App bottom sheet - A Protocol Oriented Approach
MIT License
641 stars 68 forks source link

How do you change the position of the initial height of the modal view? #33

Closed lingxiao closed 4 years ago

lingxiao commented 4 years ago

In the default behavior, the modal view pops up to fill 3/4 of the screen. In my particular use case, it'd be nice of the view only fill the bottom 1/4 of the screen. Changing the initial height and y in didContainerCreate has no effect:

` sheetCoordinator.addSheet(modal, to: self, didContainerCreate: { container in

        let f = self.view.frame

        container.frame = CGRect(
              x: 0
            , y: f.height*3/4 
            , width: f.width
            , height: f.height/4

        )`
OfTheWolf commented 4 years ago

implement UBottomSheetCoordinatorDataSource method in your view controller to modify. sheetPositions and initialPosition methods are what you are looking for.

public protocol UBottomSheetCoordinatorDataSource: class {
    ///Gesture end animation
    var animator: Animatable? {get}

    ///Sheet positions. For example top, middle, bottom y values.
    func sheetPositions(_ availableHeight: CGFloat) -> [CGFloat]

    ///Initial sheet y position.
    func initialPosition(_ availableHeight: CGFloat) -> CGFloat

    /**
     Top rubber band logic over top limit, min sheet height.

     - parameter total: total distance from the top limit
     - parameter limit: top limit or min sheet height
    */
    func rubberBandLogicTop(_ total: CGFloat, _ limit: CGFloat) -> CGFloat

   /**
     Bottom rubber band logic below bottom limit, max sheet height.

      - parameter total: total distance from the bottom limit
      - parameter limit: bottom limit or max sheet height
     */
    func rubberBandLogicBottom(_ total: CGFloat, _ limit: CGFloat) -> CGFloat
}