• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

gordontucker/FittedSheets: Bottom sheets for iOS

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

gordontucker/FittedSheets

开源软件地址:

https://github.com/gordontucker/FittedSheets

开源编程语言:

Swift 99.4%

开源软件介绍:

FittedSheets

Bottom sheets for iOS

Bitrise Status

Minimum requirement:
iOSVersion SwiftVersion XcodeVersion

About

This project is to enable easily presenting view controllers in a bottom sheet that supports scrollviews and multiple sizes. Contributions and feedback are very welcome.

The bottom sheet tries to be smart about the height it takes. If the view controller is smaller than the sizes specified, it will only grow as large as the intrinsic height of the presented view controller. If it is larger, it will stop at each height specified in the initializer or setSizes function.

Intrinsic Heights Fullscreen Modal True Fullscreen Scrolling Inline
Intrinsic Heights Fullscreen Modal True Fullscreen Scrolling Inline

Usage

Some options can only be set when setting up the fitted sheets. These are set in the SheetOptions property of the constructor.

The constructor is init(controller:, sizes:, options:). Sizes is optional, but if specified, the first size in the array will determine the initial size of the sheet. Options is also optional, if not specified, the default options will be used.

Using default settings

import FittedSheets

let controller = MyViewController()

let sheetController = SheetViewController(controller: controller)

self.present(sheetController, animated: true, completion: nil) 

Customizing settings

let controller = MyViewController()

let options = SheetOptions(
    // The full height of the pull bar. The presented view controller will treat this area as a safearea inset on the top
    pullBarHeight: 24,
    
    // The corner radius of the shrunken presenting view controller
    presentingViewCornerRadius: 20, 
    
    // Extends the background behind the pull bar or not
    shouldExtendBackground: true,
    
    // Attempts to use intrinsic heights on navigation controllers. This does not work well in combination with keyboards without your code handling it.
    setIntrinsicHeightOnNavigationControllers: true, 
    
    // Pulls the view controller behind the safe area top, especially useful when embedding navigation controllers
    useFullScreenMode: true,
    
    // Shrinks the presenting view controller, similar to the native modal
    shrinkPresentingViewController: true,
    
    // Determines if using inline mode or not
    useInlineMode: false,
    
    // Adds a padding on the left and right of the sheet with this amount. Defaults to zero (no padding)
    horizontalPadding: 0,
    
    // Sets the maximum width allowed for the sheet. This defaults to nil and doesn't limit the width.
    maxWidth: nil
)

let sheetController = SheetViewController(
    controller: controller, 
    sizes: [.intrinsic, .percent(0.25), .fixed(200), .fullScreen])
    
    
// The size of the grip in the pull bar
sheetController.gripSize = CGSize(width: 50, height: 6)

// The color of the grip on the pull bar
sheetController.gripColor = UIColor(white: 0.868, alpha: 1)

// The corner radius of the sheet
sheetController.cornerRadius = 20
    
// minimum distance above the pull bar, prevents bar from coming right up to the edge of the screen
sheetController.minimumSpaceAbovePullBar = 0 

// Set the pullbar's background explicitly
sheetController.pullBarBackgroundColor = UIColor.blue

// Determine if the rounding should happen on the pullbar or the presented controller only (should only be true when the pull bar's background color is .clear)
sheetController.treatPullBarAsClear = false

// Disable the dismiss on background tap functionality
sheetController.dismissOnOverlayTap = false

// Disable the ability to pull down to dismiss the modal
sheetController.dismissOnPull = false

/// Allow pulling past the maximum height and bounce back. Defaults to true.
sheetController.allowPullingPastMaxHeight = false

/// Automatically grow/move the sheet to accomidate the keyboard. Defaults to true.
sheetController.autoAdjustToKeyboard = true

// Color of the sheet anywhere the child view controller may not show (or is transparent), such as behind the keyboard currently
sheetController.contentBackgroundColor

// Change the overlay color
sheetController.overlayColor = UIColor.red

self.present(sheetController, animated: false, completion: nil)

Handling dismiss events

let sheet = SheetViewController(controller: controller, sizes: [.fixed(420), .fullScreen])
sheet.shouldDismiss = { _ in
// This is called just before the sheet is dismissed. Return false to prevent the build in dismiss events
    return true
}
sheet.didDismiss = { _ in
    // This is called after the sheet is dismissed
}
self.present(sheet, animated: false, completion: nil)

**

Inline presentation

Starting with version 2.0.0, the ability to present inline was added. THis allows recreating behaviours like Maps

let controller = MyViewController()

let options = SheetOptions(
    useInlineMode: true
)

let sheetController = SheetViewController(controller: controller, sizes: [.percent(0.3), .fullscreen], options: options)
sheetController.allowGestureThroughOverlay = true

// animate in
sheetController.animateIn(to: view, in: self)

Scrolling

/// This should be called by any child view controller that expects the sheet to use be able to expand/collapse when the scroll view is at the top.
func handleScrollView(_ scrollView: UIScrollView)

There is an extension on UIViewController that gives you a sheetViewController that attempts to find the current SheetViewController so you can attach like this:

override func viewDidLoad() {
  super.viewDidLoad()
  
  self.sheetViewController!.handleScrollView(self.scrollView) // or tableView/collectionView/etc
}

Package Management

We support cocoapods, carthage, and SPM.

Cocoapods Add this to your podfile to add FittedSheets to your project.

pod 'FittedSheets'

License

FittedSheets uses the MIT License:

Please see included LICENSE file.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap