├── .DS_Store ├── preview.gif ├── AYPannel.xcodeproj ├── project.xcworkspace │ └── contents.xcworkspacedata ├── xcuserdata │ └── anyuan.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── project.pbxproj ├── AYPannel ├── ViewController.h ├── AppDelegate.h ├── AYPrimaryContentViewController.h ├── main.m ├── AYDrawerContentViewController.h ├── AYPassthroughScrollView.h ├── AYPrimaryContentViewController.m ├── AYPassthroughScrollView.m ├── ViewController.m ├── Info.plist ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── Main.storyboard │ └── LaunchScreen.storyboard ├── AYPannelViewController.h ├── AppDelegate.m ├── AYDrawerContentViewController.m └── AYPannelViewController.m ├── README.md ├── LICENSE └── .gitignore /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnYuan/AYPanel/HEAD/.DS_Store -------------------------------------------------------------------------------- /preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnYuan/AYPanel/HEAD/preview.gif -------------------------------------------------------------------------------- /AYPannel.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AYPannel/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // AYPannel 4 | // 5 | // Created by anyuan on 12/12/2017. 6 | // Copyright © 2017 anyuan. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /AYPannel/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // AYPannel 4 | // 5 | // Created by anyuan on 12/12/2017. 6 | // Copyright © 2017 anyuan. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /AYPannel/AYPrimaryContentViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // AYPrimaryContentViewController.h 3 | // AYPannel 4 | // 5 | // Created by anyuan on 13/12/2017. 6 | // Copyright © 2017 anyuan. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol AYPannelPrimaryDelegate; 12 | 13 | @interface AYPrimaryContentViewController : UIViewController 14 | @end 15 | -------------------------------------------------------------------------------- /AYPannel/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // AYPannel 4 | // 5 | // Created by anyuan on 12/12/2017. 6 | // Copyright © 2017 anyuan. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AYPannel.xcodeproj/xcuserdata/anyuan.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | AYPannel.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /AYPannel/AYDrawerContentViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // AYDrawerContentViewController.h 3 | // AYPannel 4 | // 5 | // Created by anyuan on 13/12/2017. 6 | // Copyright © 2017 anyuan. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AYPannelViewController.h" 12 | 13 | @protocol AYPannelDrawerDelegate; 14 | 15 | 16 | 17 | @interface AYDrawerContentViewController : UIViewController 18 | @property (nonatomic, weak) id drawerScrollDelegate; 19 | @end 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AYPannel 2 | 3 | inspired by [Pulley](https://github.com/52inc/Pulley) 4 | 5 | 6 | preview: 7 | 8 | ![](/preview.gif) 9 | 10 | 11 | TODO: 12 | - [X] pass through touch to scroll view. 13 | - [X] 向下滑动时,不顺滑问题(需要滑动两次) 14 | - [X] 主视图接受时间传递,drawer透传事件给主视图 15 | - [X] 与drawer内部scrollview(tableview, collectionview)解耦方便后续使用 16 | - [X] 外界可动态定制部分展示的高度 17 | - [X] 适配iPhone X 18 | - [X] 黑色蒙层添加 19 | - [X] 阴影和圆角 20 | - [X] blurView添加 21 | - [X] 代码整理 22 | - [X] 增加分级拉动,多级,单级 23 | - [X] 顺滑拖动 24 | - [X] 支持外部定制drawer view样式 25 | 26 | TODO: 27 | [ISHPullUp](https://github.com/iosphere/ISHPullUp) 28 | -------------------------------------------------------------------------------- /AYPannel/AYPassthroughScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // PulleyPassthroughScrollView.h 3 | // XPannel 4 | // 5 | // Created by anyuan on 12/12/2017. 6 | // Copyright © 2017 anyuan. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class AYPassthroughScrollView; 12 | 13 | @protocol AYPassthroughScrollViewDelegate 14 | 15 | - (BOOL)shouldTouchPassthroughScrollView:(AYPassthroughScrollView *)scrollView 16 | point:(CGPoint)point; 17 | 18 | - (UIView *)viewToReceiveTouch:(AYPassthroughScrollView *)scrollView 19 | point:(CGPoint)point; 20 | @end 21 | 22 | @interface AYPassthroughScrollView : UIScrollView 23 | @property (nonatomic, weak) id touchDelegate; 24 | @end 25 | -------------------------------------------------------------------------------- /AYPannel/AYPrimaryContentViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // AYPrimaryContentViewController.m 3 | // AYPannel 4 | // 5 | // Created by anyuan on 13/12/2017. 6 | // Copyright © 2017 anyuan. All rights reserved. 7 | // 8 | 9 | #import "AYPrimaryContentViewController.h" 10 | #import "AYPannelViewController.h" 11 | 12 | @interface AYPrimaryContentViewController () 13 | @property (nonatomic, strong) UISwitch *primarySwitch; 14 | @end 15 | 16 | @implementation AYPrimaryContentViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | 21 | [self.view addSubview:self.primarySwitch]; 22 | 23 | self.view.backgroundColor = [UIColor whiteColor]; 24 | } 25 | 26 | - (void)viewDidLayoutSubviews { 27 | [super viewDidLayoutSubviews]; 28 | self.primarySwitch.frame = CGRectMake(10, 100, 50, 50); 29 | } 30 | 31 | - (UISwitch *)primarySwitch { 32 | if (!_primarySwitch) { 33 | _primarySwitch = [[UISwitch alloc] initWithFrame:CGRectZero]; 34 | } 35 | return _primarySwitch; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /AYPannel/AYPassthroughScrollView.m: -------------------------------------------------------------------------------- 1 | // 2 | // PulleyPassthroughScrollView.m 3 | // XPannel 4 | // 5 | // Created by anyuan on 12/12/2017. 6 | // Copyright © 2017 anyuan. All rights reserved. 7 | // 8 | 9 | #import "AYPassthroughScrollView.h" 10 | 11 | @implementation AYPassthroughScrollView 12 | 13 | #pragma mark - Override 14 | - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { 15 | if (self.touchDelegate) { 16 | if ([self.touchDelegate shouldTouchPassthroughScrollView:self point:point]) { 17 | UIView *view = [self.touchDelegate viewToReceiveTouch:self point:point]; 18 | CGPoint p = [view convertPoint:point fromView:self]; 19 | return [view hitTest:p withEvent:event]; 20 | } 21 | } 22 | return [super hitTest:point withEvent:event]; 23 | } 24 | 25 | 26 | //如果scroll view上有button,优先滚动 27 | - (BOOL)touchesShouldCancelInContentView:(UIView *)view 28 | { 29 | if ( [view isKindOfClass:[UIButton class]] ) { 30 | return YES; 31 | } 32 | 33 | return [super touchesShouldCancelInContentView:view]; 34 | } 35 | @end 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Anyuan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /AYPannel/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // XPannel 4 | // 5 | // Created by anyuan on 11/12/2017. 6 | // Copyright © 2017 anyuan. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "AYPannelViewController.h" 11 | #import "AYPrimaryContentViewController.h" 12 | #import "AYDrawerContentViewController.h" 13 | 14 | @interface ViewController () 15 | @property (nonatomic, strong) AYPannelViewController *xPannelViewController; 16 | @end 17 | 18 | @implementation ViewController 19 | 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | self.view.backgroundColor = [UIColor greenColor]; 23 | 24 | 25 | AYPrimaryContentViewController *p = [AYPrimaryContentViewController new]; 26 | AYDrawerContentViewController *d = [AYDrawerContentViewController new]; 27 | self.xPannelViewController = [[AYPannelViewController alloc] initWithPrimaryContentViewController:p drawerContentViewController:d]; 28 | 29 | d.drawerScrollDelegate = self.xPannelViewController; 30 | 31 | [self addChildViewController:self.xPannelViewController]; 32 | self.xPannelViewController.view.frame = self.view.bounds; 33 | [self.view addSubview:self.xPannelViewController.view]; 34 | 35 | } 36 | 37 | @end 38 | 39 | -------------------------------------------------------------------------------- /AYPannel/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | # Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots 56 | fastlane/test_output 57 | 58 | # Code Injection 59 | # 60 | # After new code Injection tools there's a generated folder /iOSInjectionProject 61 | # https://github.com/johnno1962/injectionforxcode 62 | 63 | iOSInjectionProject/ 64 | /AYPannel.xcodeproj/project.xcworkspace/xcuserdata/anyuan.xcuserdatad/UserInterfaceState.xcuserstate 65 | -------------------------------------------------------------------------------- /AYPannel/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /AYPannel/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /AYPannel/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /AYPannel/AYPannelViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // XPannelViewController.h 3 | // XPannel 4 | // 5 | // Created by anyuan on 11/12/2017. 6 | // Copyright © 2017 anyuan. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSUInteger, AYPannelPosition) { 12 | AYPannelPositionClosed, //不在可视范围 13 | AYPannelPositionCollapsed,//收起 14 | AYPannelPositionPartiallyRevealed, //部分展开 15 | AYPannelPositionOpen,//全部展开 16 | }; 17 | 18 | @class AYPannelViewController; 19 | 20 | static CGFloat kAYTopInset = 20.0f; 21 | 22 | //通知外界drawerPosition发生变化 23 | @protocol AYPannelDrawerDelegate 24 | @property (nonatomic, strong) UIView *view; 25 | 26 | - (void)drawerPositionDidChange:(AYPannelViewController *)drawer; 27 | @optional 28 | - (void)drawerDraggingProgress:(CGFloat)progress;//0 - 1 29 | 30 | - (CGFloat)collapsedDrawerHeight; 31 | - (CGFloat)partialRevealDrawerHeight; 32 | - (NSSet *)supportPannelPosition; // 返回支持位置的AYPannelPosition枚举的NSNumber对象, 如果不实现或者返回空,就默认是所有位置都支持 33 | 34 | - (UIVisualEffectView *)drawerBackgroundVisualEffectView; // 如果要展示毛玻璃效果,上层view需要设置为透明; 不需要返回nil即可 35 | - (CGFloat)drawerCornerRadius; //是否需要圆角, 如果返回0.0则不需要圆角, 此处设置圆角,其他使用圆角位置自动设置,如黑色蒙层 36 | - (UIView *)backgroundDimmingView; //蒙层View, 只需要初始化UIView,设置蒙层颜色即可, 不需要蒙层,返回nil即可 37 | @end 38 | 39 | @protocol AYPannelPrimaryDelegate 40 | @property (nonatomic, strong) UIView *view; 41 | @end 42 | 43 | //Drawer 滚动回调 44 | @protocol AYDrawerScrollViewDelegate 45 | - (void)drawerScrollViewDidScroll:(UIScrollView *)scrollView; 46 | @end 47 | 48 | @interface AYPannelViewController : UIViewController 49 | 50 | @property (nonatomic, assign) AYPannelPosition currentPosition; 51 | @property (nonatomic, assign) BOOL shouldScrollDrawerScrollView; 52 | 53 | - (instancetype)initWithPrimaryContentViewController:(id)primaryContentViewController 54 | drawerContentViewController:(id)drawerContentViewController; 55 | @end 56 | 57 | 58 | -------------------------------------------------------------------------------- /AYPannel/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // AYPannel 4 | // 5 | // Created by anyuan on 12/12/2017. 6 | // Copyright © 2017 anyuan. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /AYPannel/AYDrawerContentViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // AYDrawerContentViewController.m 3 | // AYPannel 4 | // 5 | // Created by anyuan on 13/12/2017. 6 | // Copyright © 2017 anyuan. All rights reserved. 7 | // 8 | 9 | #import "AYDrawerContentViewController.h" 10 | #import "AYPannelViewController.h" 11 | 12 | @interface AYDrawerContentViewController () 13 | @property (nonatomic, strong) UIView *headerView; 14 | @property (nonatomic, strong) UITableView *tableView; 15 | @property (nonatomic, strong) UIButton *button; 16 | @end 17 | 18 | @implementation AYDrawerContentViewController 19 | 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | 23 | [self.view addSubview:self.headerView]; 24 | [self.view addSubview:self.tableView]; 25 | self.view.backgroundColor = [UIColor blueColor]; 26 | 27 | [self.tableView setScrollEnabled:NO]; 28 | self.tableView.bounces = NO; 29 | 30 | [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"table view cell"]; 31 | } 32 | 33 | - (void)viewDidLayoutSubviews { 34 | [super viewDidLayoutSubviews]; 35 | 36 | self.headerView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 60); 37 | self.tableView.frame = CGRectMake(0, 60, self.view.bounds.size.width, self.view.bounds.size.height - 60 - kAYTopInset); 38 | self.button.frame = CGRectMake(100, 0, 50, 50); 39 | } 40 | #pragma mark - UITableViewDataSource 41 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 42 | return 1; 43 | } 44 | 45 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 46 | return 30; 47 | } 48 | 49 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 50 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"table view cell"]; 51 | cell.backgroundColor = [UIColor clearColor]; 52 | cell.textLabel.text = [NSString stringWithFormat:@"This is indexPath %ld", (long)indexPath.row]; 53 | return cell; 54 | } 55 | 56 | #pragma mark - UITableViewDelegate 57 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 58 | return 80; 59 | } 60 | 61 | #pragma mark - AYPannelViewControllerDelegate 62 | - (void)drawerPositionDidChange:(AYPannelViewController *)drawer { 63 | if (drawer.currentPosition == AYPannelPositionOpen) { 64 | [self.tableView setScrollEnabled:YES]; 65 | } else { 66 | [self.tableView setScrollEnabled:NO]; 67 | } 68 | } 69 | 70 | - (void)drawerDraggingProgress:(CGFloat)progress { 71 | // NSLog(@"###### dragging progress is %f", progress); 72 | } 73 | 74 | - (CGFloat)collapsedDrawerHeight { 75 | return 68.0f; 76 | } 77 | 78 | - (CGFloat)partialRevealDrawerHeight { 79 | return 264.0f; 80 | } 81 | 82 | - (NSSet *)supportPannelPosition { 83 | NSArray *array = @[@(AYPannelPositionCollapsed), @(AYPannelPositionPartiallyRevealed), @(AYPannelPositionOpen),@(AYPannelPositionClosed)]; 84 | return [NSSet setWithArray:array]; 85 | } 86 | 87 | - (UIVisualEffectView *)drawerBackgroundVisualEffectView { 88 | UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]; 89 | UIVisualEffectView *drawerBackgroundVisualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; 90 | drawerBackgroundVisualEffectView.clipsToBounds = YES; 91 | return drawerBackgroundVisualEffectView; 92 | } 93 | 94 | - (CGFloat)drawerCornerRadius { 95 | return 13.0f; 96 | } 97 | 98 | - (UIView *)backgroundDimmingView { 99 | UIView *backgroundDimmingView = [[UIView alloc] init]; 100 | backgroundDimmingView.backgroundColor = [UIColor blackColor]; 101 | return backgroundDimmingView; 102 | } 103 | 104 | #pragma mark - UIScrollViewDelegate 105 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 106 | [self.drawerScrollDelegate drawerScrollViewDidScroll:scrollView]; 107 | } 108 | 109 | 110 | #pragma mark - Getter 111 | 112 | - (UITableView *)tableView { 113 | if (!_tableView) { 114 | _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; 115 | _tableView.dataSource = self; 116 | _tableView.delegate = self; 117 | _tableView.backgroundColor = [UIColor clearColor]; 118 | } 119 | return _tableView; 120 | } 121 | 122 | - (UIView *)headerView { 123 | if (!_headerView) { 124 | _headerView = [[UIView alloc] init]; 125 | _headerView.backgroundColor = [UIColor clearColor]; 126 | 127 | _button = [UIButton buttonWithType:UIButtonTypeCustom]; 128 | [_button setTitle:@"button" forState:UIControlStateNormal]; 129 | [_button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside]; 130 | [_headerView addSubview:_button]; 131 | } 132 | return _headerView; 133 | } 134 | 135 | - (void)buttonPressed { 136 | NSLog(@"################"); 137 | } 138 | @end 139 | -------------------------------------------------------------------------------- /AYPannel.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D1CF0DA01FDFBD3B0081DDD4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D1CF0D9F1FDFBD3B0081DDD4 /* AppDelegate.m */; }; 11 | D1CF0DA31FDFBD3B0081DDD4 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D1CF0DA21FDFBD3B0081DDD4 /* ViewController.m */; }; 12 | D1CF0DA61FDFBD3B0081DDD4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D1CF0DA41FDFBD3B0081DDD4 /* Main.storyboard */; }; 13 | D1CF0DA81FDFBD3B0081DDD4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D1CF0DA71FDFBD3B0081DDD4 /* Assets.xcassets */; }; 14 | D1CF0DAB1FDFBD3B0081DDD4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D1CF0DA91FDFBD3B0081DDD4 /* LaunchScreen.storyboard */; }; 15 | D1CF0DAE1FDFBD3B0081DDD4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D1CF0DAD1FDFBD3B0081DDD4 /* main.m */; }; 16 | D1CF0DB81FDFBD5C0081DDD4 /* AYPassthroughScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = D1CF0DB41FDFBD5C0081DDD4 /* AYPassthroughScrollView.m */; }; 17 | D1CF0DB91FDFBD5C0081DDD4 /* AYPannelViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D1CF0DB61FDFBD5C0081DDD4 /* AYPannelViewController.m */; }; 18 | D1CF0DBC1FE10BD80081DDD4 /* AYDrawerContentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D1CF0DBB1FE10BD80081DDD4 /* AYDrawerContentViewController.m */; }; 19 | D1CF0DBF1FE10E080081DDD4 /* AYPrimaryContentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D1CF0DBE1FE10E080081DDD4 /* AYPrimaryContentViewController.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | D1CF0D9B1FDFBD3B0081DDD4 /* AYPannel.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AYPannel.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | D1CF0D9E1FDFBD3B0081DDD4 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 25 | D1CF0D9F1FDFBD3B0081DDD4 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 26 | D1CF0DA11FDFBD3B0081DDD4 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 27 | D1CF0DA21FDFBD3B0081DDD4 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 28 | D1CF0DA51FDFBD3B0081DDD4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 29 | D1CF0DA71FDFBD3B0081DDD4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 30 | D1CF0DAA1FDFBD3B0081DDD4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 31 | D1CF0DAC1FDFBD3B0081DDD4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | D1CF0DAD1FDFBD3B0081DDD4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 33 | D1CF0DB41FDFBD5C0081DDD4 /* AYPassthroughScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AYPassthroughScrollView.m; sourceTree = ""; }; 34 | D1CF0DB51FDFBD5C0081DDD4 /* AYPannelViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AYPannelViewController.h; sourceTree = ""; }; 35 | D1CF0DB61FDFBD5C0081DDD4 /* AYPannelViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AYPannelViewController.m; sourceTree = ""; }; 36 | D1CF0DB71FDFBD5C0081DDD4 /* AYPassthroughScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AYPassthroughScrollView.h; sourceTree = ""; }; 37 | D1CF0DBA1FE10BD80081DDD4 /* AYDrawerContentViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AYDrawerContentViewController.h; sourceTree = ""; }; 38 | D1CF0DBB1FE10BD80081DDD4 /* AYDrawerContentViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AYDrawerContentViewController.m; sourceTree = ""; }; 39 | D1CF0DBD1FE10E080081DDD4 /* AYPrimaryContentViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AYPrimaryContentViewController.h; sourceTree = ""; }; 40 | D1CF0DBE1FE10E080081DDD4 /* AYPrimaryContentViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AYPrimaryContentViewController.m; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | D1CF0D981FDFBD3B0081DDD4 /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | D1CF0D921FDFBD3B0081DDD4 = { 55 | isa = PBXGroup; 56 | children = ( 57 | D1CF0D9D1FDFBD3B0081DDD4 /* AYPannel */, 58 | D1CF0D9C1FDFBD3B0081DDD4 /* Products */, 59 | ); 60 | sourceTree = ""; 61 | }; 62 | D1CF0D9C1FDFBD3B0081DDD4 /* Products */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | D1CF0D9B1FDFBD3B0081DDD4 /* AYPannel.app */, 66 | ); 67 | name = Products; 68 | sourceTree = ""; 69 | }; 70 | D1CF0D9D1FDFBD3B0081DDD4 /* AYPannel */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | D1CF0D9E1FDFBD3B0081DDD4 /* AppDelegate.h */, 74 | D1CF0D9F1FDFBD3B0081DDD4 /* AppDelegate.m */, 75 | D1CF0DA11FDFBD3B0081DDD4 /* ViewController.h */, 76 | D1CF0DA21FDFBD3B0081DDD4 /* ViewController.m */, 77 | D1CF0DBD1FE10E080081DDD4 /* AYPrimaryContentViewController.h */, 78 | D1CF0DBE1FE10E080081DDD4 /* AYPrimaryContentViewController.m */, 79 | D1CF0DBA1FE10BD80081DDD4 /* AYDrawerContentViewController.h */, 80 | D1CF0DBB1FE10BD80081DDD4 /* AYDrawerContentViewController.m */, 81 | D1CF0DB51FDFBD5C0081DDD4 /* AYPannelViewController.h */, 82 | D1CF0DB61FDFBD5C0081DDD4 /* AYPannelViewController.m */, 83 | D1CF0DB71FDFBD5C0081DDD4 /* AYPassthroughScrollView.h */, 84 | D1CF0DB41FDFBD5C0081DDD4 /* AYPassthroughScrollView.m */, 85 | D1CF0DA41FDFBD3B0081DDD4 /* Main.storyboard */, 86 | D1CF0DA71FDFBD3B0081DDD4 /* Assets.xcassets */, 87 | D1CF0DA91FDFBD3B0081DDD4 /* LaunchScreen.storyboard */, 88 | D1CF0DAC1FDFBD3B0081DDD4 /* Info.plist */, 89 | D1CF0DAD1FDFBD3B0081DDD4 /* main.m */, 90 | ); 91 | path = AYPannel; 92 | sourceTree = ""; 93 | }; 94 | /* End PBXGroup section */ 95 | 96 | /* Begin PBXNativeTarget section */ 97 | D1CF0D9A1FDFBD3B0081DDD4 /* AYPannel */ = { 98 | isa = PBXNativeTarget; 99 | buildConfigurationList = D1CF0DB11FDFBD3B0081DDD4 /* Build configuration list for PBXNativeTarget "AYPannel" */; 100 | buildPhases = ( 101 | D1CF0D971FDFBD3B0081DDD4 /* Sources */, 102 | D1CF0D981FDFBD3B0081DDD4 /* Frameworks */, 103 | D1CF0D991FDFBD3B0081DDD4 /* Resources */, 104 | ); 105 | buildRules = ( 106 | ); 107 | dependencies = ( 108 | ); 109 | name = AYPannel; 110 | productName = AYPannel; 111 | productReference = D1CF0D9B1FDFBD3B0081DDD4 /* AYPannel.app */; 112 | productType = "com.apple.product-type.application"; 113 | }; 114 | /* End PBXNativeTarget section */ 115 | 116 | /* Begin PBXProject section */ 117 | D1CF0D931FDFBD3B0081DDD4 /* Project object */ = { 118 | isa = PBXProject; 119 | attributes = { 120 | LastUpgradeCheck = 0920; 121 | ORGANIZATIONNAME = anyuan; 122 | TargetAttributes = { 123 | D1CF0D9A1FDFBD3B0081DDD4 = { 124 | CreatedOnToolsVersion = 9.2; 125 | ProvisioningStyle = Automatic; 126 | }; 127 | }; 128 | }; 129 | buildConfigurationList = D1CF0D961FDFBD3B0081DDD4 /* Build configuration list for PBXProject "AYPannel" */; 130 | compatibilityVersion = "Xcode 8.0"; 131 | developmentRegion = en; 132 | hasScannedForEncodings = 0; 133 | knownRegions = ( 134 | en, 135 | Base, 136 | ); 137 | mainGroup = D1CF0D921FDFBD3B0081DDD4; 138 | productRefGroup = D1CF0D9C1FDFBD3B0081DDD4 /* Products */; 139 | projectDirPath = ""; 140 | projectRoot = ""; 141 | targets = ( 142 | D1CF0D9A1FDFBD3B0081DDD4 /* AYPannel */, 143 | ); 144 | }; 145 | /* End PBXProject section */ 146 | 147 | /* Begin PBXResourcesBuildPhase section */ 148 | D1CF0D991FDFBD3B0081DDD4 /* Resources */ = { 149 | isa = PBXResourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | D1CF0DAB1FDFBD3B0081DDD4 /* LaunchScreen.storyboard in Resources */, 153 | D1CF0DA81FDFBD3B0081DDD4 /* Assets.xcassets in Resources */, 154 | D1CF0DA61FDFBD3B0081DDD4 /* Main.storyboard in Resources */, 155 | ); 156 | runOnlyForDeploymentPostprocessing = 0; 157 | }; 158 | /* End PBXResourcesBuildPhase section */ 159 | 160 | /* Begin PBXSourcesBuildPhase section */ 161 | D1CF0D971FDFBD3B0081DDD4 /* Sources */ = { 162 | isa = PBXSourcesBuildPhase; 163 | buildActionMask = 2147483647; 164 | files = ( 165 | D1CF0DB81FDFBD5C0081DDD4 /* AYPassthroughScrollView.m in Sources */, 166 | D1CF0DBC1FE10BD80081DDD4 /* AYDrawerContentViewController.m in Sources */, 167 | D1CF0DB91FDFBD5C0081DDD4 /* AYPannelViewController.m in Sources */, 168 | D1CF0DBF1FE10E080081DDD4 /* AYPrimaryContentViewController.m in Sources */, 169 | D1CF0DA31FDFBD3B0081DDD4 /* ViewController.m in Sources */, 170 | D1CF0DAE1FDFBD3B0081DDD4 /* main.m in Sources */, 171 | D1CF0DA01FDFBD3B0081DDD4 /* AppDelegate.m in Sources */, 172 | ); 173 | runOnlyForDeploymentPostprocessing = 0; 174 | }; 175 | /* End PBXSourcesBuildPhase section */ 176 | 177 | /* Begin PBXVariantGroup section */ 178 | D1CF0DA41FDFBD3B0081DDD4 /* Main.storyboard */ = { 179 | isa = PBXVariantGroup; 180 | children = ( 181 | D1CF0DA51FDFBD3B0081DDD4 /* Base */, 182 | ); 183 | name = Main.storyboard; 184 | sourceTree = ""; 185 | }; 186 | D1CF0DA91FDFBD3B0081DDD4 /* LaunchScreen.storyboard */ = { 187 | isa = PBXVariantGroup; 188 | children = ( 189 | D1CF0DAA1FDFBD3B0081DDD4 /* Base */, 190 | ); 191 | name = LaunchScreen.storyboard; 192 | sourceTree = ""; 193 | }; 194 | /* End PBXVariantGroup section */ 195 | 196 | /* Begin XCBuildConfiguration section */ 197 | D1CF0DAF1FDFBD3B0081DDD4 /* Debug */ = { 198 | isa = XCBuildConfiguration; 199 | buildSettings = { 200 | ALWAYS_SEARCH_USER_PATHS = NO; 201 | CLANG_ANALYZER_NONNULL = YES; 202 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 203 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 204 | CLANG_CXX_LIBRARY = "libc++"; 205 | CLANG_ENABLE_MODULES = YES; 206 | CLANG_ENABLE_OBJC_ARC = YES; 207 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 208 | CLANG_WARN_BOOL_CONVERSION = YES; 209 | CLANG_WARN_COMMA = YES; 210 | CLANG_WARN_CONSTANT_CONVERSION = YES; 211 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 212 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 213 | CLANG_WARN_EMPTY_BODY = YES; 214 | CLANG_WARN_ENUM_CONVERSION = YES; 215 | CLANG_WARN_INFINITE_RECURSION = YES; 216 | CLANG_WARN_INT_CONVERSION = YES; 217 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 218 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 219 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 220 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 221 | CLANG_WARN_STRICT_PROTOTYPES = YES; 222 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 223 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 224 | CLANG_WARN_UNREACHABLE_CODE = YES; 225 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 226 | CODE_SIGN_IDENTITY = "iPhone Developer"; 227 | COPY_PHASE_STRIP = NO; 228 | DEBUG_INFORMATION_FORMAT = dwarf; 229 | ENABLE_STRICT_OBJC_MSGSEND = YES; 230 | ENABLE_TESTABILITY = YES; 231 | GCC_C_LANGUAGE_STANDARD = gnu11; 232 | GCC_DYNAMIC_NO_PIC = NO; 233 | GCC_NO_COMMON_BLOCKS = YES; 234 | GCC_OPTIMIZATION_LEVEL = 0; 235 | GCC_PREPROCESSOR_DEFINITIONS = ( 236 | "DEBUG=1", 237 | "$(inherited)", 238 | ); 239 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 240 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 241 | GCC_WARN_UNDECLARED_SELECTOR = YES; 242 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 243 | GCC_WARN_UNUSED_FUNCTION = YES; 244 | GCC_WARN_UNUSED_VARIABLE = YES; 245 | IPHONEOS_DEPLOYMENT_TARGET = 11.2; 246 | MTL_ENABLE_DEBUG_INFO = YES; 247 | ONLY_ACTIVE_ARCH = YES; 248 | SDKROOT = iphoneos; 249 | }; 250 | name = Debug; 251 | }; 252 | D1CF0DB01FDFBD3B0081DDD4 /* Release */ = { 253 | isa = XCBuildConfiguration; 254 | buildSettings = { 255 | ALWAYS_SEARCH_USER_PATHS = NO; 256 | CLANG_ANALYZER_NONNULL = YES; 257 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 258 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 259 | CLANG_CXX_LIBRARY = "libc++"; 260 | CLANG_ENABLE_MODULES = YES; 261 | CLANG_ENABLE_OBJC_ARC = YES; 262 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 263 | CLANG_WARN_BOOL_CONVERSION = YES; 264 | CLANG_WARN_COMMA = YES; 265 | CLANG_WARN_CONSTANT_CONVERSION = YES; 266 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 267 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 268 | CLANG_WARN_EMPTY_BODY = YES; 269 | CLANG_WARN_ENUM_CONVERSION = YES; 270 | CLANG_WARN_INFINITE_RECURSION = YES; 271 | CLANG_WARN_INT_CONVERSION = YES; 272 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 273 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 274 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 275 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 276 | CLANG_WARN_STRICT_PROTOTYPES = YES; 277 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 278 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 279 | CLANG_WARN_UNREACHABLE_CODE = YES; 280 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 281 | CODE_SIGN_IDENTITY = "iPhone Developer"; 282 | COPY_PHASE_STRIP = NO; 283 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 284 | ENABLE_NS_ASSERTIONS = NO; 285 | ENABLE_STRICT_OBJC_MSGSEND = YES; 286 | GCC_C_LANGUAGE_STANDARD = gnu11; 287 | GCC_NO_COMMON_BLOCKS = YES; 288 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 289 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 290 | GCC_WARN_UNDECLARED_SELECTOR = YES; 291 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 292 | GCC_WARN_UNUSED_FUNCTION = YES; 293 | GCC_WARN_UNUSED_VARIABLE = YES; 294 | IPHONEOS_DEPLOYMENT_TARGET = 11.2; 295 | MTL_ENABLE_DEBUG_INFO = NO; 296 | SDKROOT = iphoneos; 297 | VALIDATE_PRODUCT = YES; 298 | }; 299 | name = Release; 300 | }; 301 | D1CF0DB21FDFBD3B0081DDD4 /* Debug */ = { 302 | isa = XCBuildConfiguration; 303 | buildSettings = { 304 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 305 | CODE_SIGN_STYLE = Automatic; 306 | DEVELOPMENT_TEAM = 2S522JJ287; 307 | INFOPLIST_FILE = AYPannel/Info.plist; 308 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 309 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 310 | PRODUCT_BUNDLE_IDENTIFIER = anyuan.AYPannel; 311 | PRODUCT_NAME = "$(TARGET_NAME)"; 312 | TARGETED_DEVICE_FAMILY = "1,2"; 313 | }; 314 | name = Debug; 315 | }; 316 | D1CF0DB31FDFBD3B0081DDD4 /* Release */ = { 317 | isa = XCBuildConfiguration; 318 | buildSettings = { 319 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 320 | CODE_SIGN_STYLE = Automatic; 321 | DEVELOPMENT_TEAM = 2S522JJ287; 322 | INFOPLIST_FILE = AYPannel/Info.plist; 323 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 324 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 325 | PRODUCT_BUNDLE_IDENTIFIER = anyuan.AYPannel; 326 | PRODUCT_NAME = "$(TARGET_NAME)"; 327 | TARGETED_DEVICE_FAMILY = "1,2"; 328 | }; 329 | name = Release; 330 | }; 331 | /* End XCBuildConfiguration section */ 332 | 333 | /* Begin XCConfigurationList section */ 334 | D1CF0D961FDFBD3B0081DDD4 /* Build configuration list for PBXProject "AYPannel" */ = { 335 | isa = XCConfigurationList; 336 | buildConfigurations = ( 337 | D1CF0DAF1FDFBD3B0081DDD4 /* Debug */, 338 | D1CF0DB01FDFBD3B0081DDD4 /* Release */, 339 | ); 340 | defaultConfigurationIsVisible = 0; 341 | defaultConfigurationName = Release; 342 | }; 343 | D1CF0DB11FDFBD3B0081DDD4 /* Build configuration list for PBXNativeTarget "AYPannel" */ = { 344 | isa = XCConfigurationList; 345 | buildConfigurations = ( 346 | D1CF0DB21FDFBD3B0081DDD4 /* Debug */, 347 | D1CF0DB31FDFBD3B0081DDD4 /* Release */, 348 | ); 349 | defaultConfigurationIsVisible = 0; 350 | defaultConfigurationName = Release; 351 | }; 352 | /* End XCConfigurationList section */ 353 | }; 354 | rootObject = D1CF0D931FDFBD3B0081DDD4 /* Project object */; 355 | } 356 | -------------------------------------------------------------------------------- /AYPannel/AYPannelViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // XPannelViewController.m 3 | // XPannel 4 | // 5 | // Created by anyuan on 11/12/2017. 6 | // Copyright © 2017 anyuan. All rights reserved. 7 | // 8 | 9 | #import "AYPannelViewController.h" 10 | #import "AYPassthroughScrollView.h" 11 | 12 | static CGFloat kAYDefaultCollapsedHeight = 68.0f; //默认收起大小 13 | static CGFloat kAYDefaultPartialRevealHeight = 264.0f; //默认部分展开大小 14 | 15 | static CGFloat kAYBounceOverflowMargin = 20.0f; 16 | static CGFloat kAYDefaultDimmingOpacity = 0.5f; 17 | 18 | static CGFloat kAYDefaultShadowOpacity = 0.1f; 19 | static CGFloat kAYDefaultShadowRadius = 3.0f; 20 | 21 | @interface AYPannelViewController () 22 | @property (nonatomic, assign) CGPoint lastDragTargetContentOffSet; //记录上次滑动位置 23 | @property (nonatomic, assign) BOOL isAnimatingDrawerPosition; 24 | 25 | @property (nonatomic, strong) UIPanGestureRecognizer *pan; //滑动手势 26 | @property (nonatomic, strong) UITapGestureRecognizer *tapGestureRecognizer; //点击手势,用于蒙层点击 27 | 28 | @property (nonatomic, strong) UIView *primaryContentContainer; //主要内容容器视图 29 | @property (nonatomic, strong) UIView *drawerContentContainer; //抽屉内容容器视图 30 | @property (nonatomic, strong) AYPassthroughScrollView *drawerScrollView; //抽屉滚动视图 31 | @property (nonatomic, strong) UIView *drawerShadowView; //阴影 32 | 33 | @property (nonatomic, strong) UIVisualEffectView *drawerBackgroundVisualEffectView; //毛玻璃效果 34 | 35 | @property (nonatomic, strong) UIView *backgroundDimmingView; //黑色蒙层 36 | 37 | @property (nonatomic, strong) id primaryContentViewController; //主视图VC 38 | @property (nonatomic, strong) id drawerContentViewController; //抽屉视图VC 39 | 40 | @property (nonatomic, strong) NSSet *supportedPostions; 41 | @end 42 | 43 | @implementation AYPannelViewController 44 | 45 | - (instancetype)initWithPrimaryContentViewController:(id)primaryContentViewController drawerContentViewController:(id)drawerContentViewController { 46 | self = [super init]; 47 | if (self) { 48 | self.primaryContentViewController = primaryContentViewController; 49 | self.drawerContentViewController = drawerContentViewController; 50 | } 51 | return self; 52 | } 53 | 54 | #pragma mark - Life Cycle 55 | - (void)viewDidLoad { 56 | 57 | [super viewDidLoad]; 58 | 59 | self.lastDragTargetContentOffSet = CGPointZero; 60 | 61 | [self.drawerScrollView addSubview:self.drawerShadowView]; 62 | 63 | if (self.drawerBackgroundVisualEffectView) { 64 | [self.drawerScrollView insertSubview:self.drawerBackgroundVisualEffectView aboveSubview:self.drawerShadowView]; 65 | self.drawerBackgroundVisualEffectView.layer.cornerRadius = [self p_cornerRadius]; 66 | } 67 | 68 | [self.drawerScrollView addSubview:self.drawerContentContainer]; 69 | 70 | self.drawerScrollView.showsVerticalScrollIndicator = NO; 71 | self.drawerScrollView.showsHorizontalScrollIndicator = NO; 72 | self.drawerScrollView.bounces = NO; 73 | self.drawerScrollView.canCancelContentTouches = YES; 74 | self.drawerScrollView.decelerationRate = UIScrollViewDecelerationRateFast; 75 | self.drawerScrollView.touchDelegate = self; 76 | 77 | self.drawerShadowView.layer.shadowOpacity = kAYDefaultShadowOpacity; 78 | self.drawerShadowView.layer.shadowRadius = kAYDefaultShadowRadius; 79 | self.drawerShadowView.backgroundColor = [UIColor clearColor]; 80 | 81 | 82 | self.pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognizerAction:)]; 83 | self.pan.delegate = self; 84 | [self.drawerScrollView addGestureRecognizer:self.pan]; 85 | 86 | [self.view addSubview:self.primaryContentContainer]; 87 | [self.view addSubview:self.backgroundDimmingView]; 88 | [self.view addSubview:self.drawerScrollView]; 89 | 90 | } 91 | 92 | - (void)viewDidLayoutSubviews { 93 | 94 | [super viewDidLayoutSubviews]; 95 | 96 | 97 | [self.primaryContentContainer addSubview:self.primaryContentViewController.view]; 98 | [self.primaryContentContainer sendSubviewToBack:self.primaryContentViewController.view]; 99 | 100 | [self.drawerContentContainer addSubview:self.drawerContentViewController.view]; 101 | [self.drawerContentContainer sendSubviewToBack:self.drawerContentViewController.view]; 102 | 103 | self.primaryContentContainer.frame = self.view.bounds; 104 | 105 | CGFloat safeAreaTopInset; 106 | CGFloat safeAreaBottomInset; 107 | 108 | if (@available(iOS 11.0, *)) { 109 | safeAreaTopInset = self.view.safeAreaInsets.top; 110 | safeAreaBottomInset = self.view.safeAreaInsets.bottom; 111 | } else { 112 | safeAreaTopInset = self.topLayoutGuide.length; 113 | safeAreaBottomInset = self.bottomLayoutGuide.length; 114 | } 115 | 116 | if (@available(iOS 11.0, *)) { 117 | self.drawerScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways; 118 | } else { 119 | self.automaticallyAdjustsScrollViewInsets = NO; 120 | self.drawerScrollView.contentInset = UIEdgeInsetsMake(0, 0, self.bottomLayoutGuide.length, 0); 121 | } 122 | NSMutableArray *drawerStops = [[NSMutableArray alloc] init]; 123 | 124 | if ([self.supportedPostions containsObject:@(AYPannelPositionCollapsed)]) { 125 | [drawerStops addObject:@([self collapsedHeight])]; 126 | } 127 | 128 | if ([self.supportedPostions containsObject:@(AYPannelPositionPartiallyRevealed)]) { 129 | [drawerStops addObject:@([self partialRevealDrawerHeight])]; 130 | } 131 | 132 | if ([self.supportedPostions containsObject:@(AYPannelPositionOpen)]) { 133 | [drawerStops addObject:@(self.drawerScrollView.bounds.size.height - kAYTopInset - safeAreaTopInset)]; 134 | } 135 | 136 | CGFloat lowestStop = [[drawerStops valueForKeyPath:@"@min.floatValue"] floatValue]; 137 | 138 | if ([self.supportedPostions containsObject:@(AYPannelPositionOpen)]) { 139 | self.drawerScrollView.frame = CGRectMake(0, kAYTopInset + safeAreaTopInset, self.view.bounds.size.width, self.view.bounds.size.height - kAYTopInset - safeAreaTopInset); 140 | } else { 141 | CGFloat adjustedTopInset = [self.supportedPostions containsObject:@(AYPannelPositionPartiallyRevealed)] ? [self partialRevealDrawerHeight] : [self collapsedHeight]; 142 | self.drawerScrollView.frame = CGRectMake(0, self.view.bounds.size.height - adjustedTopInset, self.view.bounds.size.width, adjustedTopInset); 143 | } 144 | 145 | 146 | self.drawerContentContainer.frame = CGRectMake(0, self.drawerScrollView.bounds.size.height - lowestStop, self.drawerScrollView.bounds.size.width, self.drawerScrollView.bounds.size.height + kAYBounceOverflowMargin); 147 | 148 | if (self.drawerBackgroundVisualEffectView) { 149 | self.drawerBackgroundVisualEffectView.frame = self.drawerContentContainer.frame; 150 | } 151 | 152 | self.drawerShadowView.frame = self.drawerContentContainer.frame; 153 | 154 | self.drawerScrollView.contentSize = CGSizeMake(self.drawerScrollView.bounds.size.width, (self.drawerScrollView.bounds.size.height - lowestStop) + self.drawerScrollView.bounds.size.height - safeAreaBottomInset); 155 | 156 | 157 | self.backgroundDimmingView.frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height + self.drawerScrollView.contentSize.height); 158 | 159 | if ([self p_needsCornerRadius]) { 160 | CGFloat cornerRadius = [self p_cornerRadius]; 161 | CGPathRef path = [UIBezierPath bezierPathWithRoundedRect:self.drawerContentContainer.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(cornerRadius, cornerRadius)].CGPath; 162 | 163 | CAShapeLayer *layer = [[CAShapeLayer alloc] init]; 164 | layer.path = path; 165 | layer.frame = self.drawerContentContainer.bounds; 166 | layer.fillColor = [UIColor whiteColor].CGColor; 167 | layer.backgroundColor = [UIColor clearColor].CGColor; 168 | self.drawerContentContainer.layer.mask = layer; 169 | self.drawerShadowView.layer.shadowPath = path; 170 | 171 | self.drawerScrollView.transform = CGAffineTransformIdentity; 172 | self.drawerContentContainer.transform = self.drawerScrollView.transform; 173 | self.drawerShadowView.transform = self.drawerScrollView.transform; 174 | 175 | [self p_maskBackgroundDimmingView]; 176 | } 177 | 178 | 179 | [self.backgroundDimmingView setHidden:NO]; 180 | 181 | 182 | [self p_setDrawerPosition:AYPannelPositionCollapsed animated:NO]; 183 | } 184 | 185 | 186 | #pragma mark - UIScrollViewDelegate 187 | 188 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 189 | 190 | 191 | if (scrollView != self.drawerScrollView) { return; } 192 | 193 | NSMutableArray *drawerStops = [[NSMutableArray alloc] init]; 194 | 195 | if ([self.supportedPostions containsObject:@(AYPannelPositionCollapsed)]) { 196 | [drawerStops addObject:@([self collapsedHeight])]; 197 | } 198 | 199 | if ([self.supportedPostions containsObject:@(AYPannelPositionPartiallyRevealed)]) { 200 | [drawerStops addObject:@([self partialRevealDrawerHeight])]; 201 | } 202 | 203 | if ([self.supportedPostions containsObject:@(AYPannelPositionOpen)]) { 204 | [drawerStops addObject:@(self.drawerScrollView.bounds.size.height)]; 205 | } 206 | 207 | CGFloat lowestStop = [[drawerStops valueForKeyPath:@"@min.floatValue"] floatValue]; 208 | 209 | 210 | if ([self.drawerContentViewController respondsToSelector:@selector(drawerDraggingProgress:)]) { 211 | 212 | CGFloat safeAreaTopInset; 213 | 214 | if (@available(iOS 11.0, *)) { 215 | safeAreaTopInset = self.view.safeAreaInsets.top; 216 | } else { 217 | safeAreaTopInset = self.topLayoutGuide.length; 218 | } 219 | 220 | CGFloat spaceToDrag = self.drawerScrollView.bounds.size.height - safeAreaTopInset - lowestStop; 221 | 222 | CGFloat dragProgress = fabs(scrollView.contentOffset.y) / spaceToDrag; 223 | if (dragProgress - 1 > FLT_EPSILON) { //in case greater than 1 224 | dragProgress = 1.0f; 225 | } 226 | NSString *p = [NSString stringWithFormat:@"%.2f", dragProgress]; 227 | [self.drawerContentViewController drawerDraggingProgress:p.floatValue]; 228 | } 229 | 230 | //蒙层颜色变化 231 | if ((scrollView.contentOffset.y - [self p_bottomSafeArea]) > ([self partialRevealDrawerHeight] - lowestStop)) { 232 | CGFloat progress; 233 | CGFloat fullRevealHeight = self.drawerScrollView.bounds.size.height; 234 | 235 | if (fullRevealHeight == [self partialRevealDrawerHeight]) { 236 | progress = 1.0; 237 | } else { 238 | progress = (scrollView.contentOffset.y - ([self partialRevealDrawerHeight] - lowestStop)) / (fullRevealHeight - [self partialRevealDrawerHeight]); 239 | } 240 | self.backgroundDimmingView.alpha = progress * kAYDefaultDimmingOpacity; 241 | [self.backgroundDimmingView setUserInteractionEnabled:YES]; 242 | } else { 243 | if (self.backgroundDimmingView.alpha >= 0.01) { 244 | self.backgroundDimmingView.alpha = 0.0; 245 | [self.backgroundDimmingView setUserInteractionEnabled:NO]; 246 | } 247 | } 248 | 249 | self.backgroundDimmingView.frame = [self p_backgroundDimmingViewFrameForDrawerPosition:scrollView.contentOffset.y + lowestStop]; 250 | } 251 | 252 | - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { 253 | if (scrollView == self.drawerScrollView) { 254 | 255 | [self p_setDrawerPosition:[self p_postionToMoveFromPostion:self.currentPosition lastDragTargetContentOffSet:self.lastDragTargetContentOffSet scrollView:self.drawerScrollView supportedPosition:self.supportedPostions] animated:YES]; 256 | } 257 | } 258 | 259 | - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { 260 | if (scrollView == self.drawerScrollView) { 261 | self.lastDragTargetContentOffSet = CGPointMake(targetContentOffset->x, targetContentOffset->y); 262 | *targetContentOffset = scrollView.contentOffset; 263 | } 264 | } 265 | 266 | #pragma mark - UIPanGestureRecognizer 267 | - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { 268 | return YES; 269 | } 270 | 271 | - (void)panGestureRecognizerAction:(UIPanGestureRecognizer *)getsutre { 272 | 273 | if (!self.shouldScrollDrawerScrollView) { return; } 274 | 275 | if (getsutre.state == UIGestureRecognizerStateChanged) { 276 | CGPoint old = [getsutre translationInView:self.drawerScrollView]; 277 | if (old.y < 0) { return; } 278 | CGPoint p = CGPointMake(0, self.drawerScrollView.frame.size.height - old.y - [self collapsedHeight]); 279 | self.lastDragTargetContentOffSet = p; 280 | [self.drawerScrollView setContentOffset:p]; 281 | } else if (getsutre.state == UIGestureRecognizerStateEnded) { 282 | self.shouldScrollDrawerScrollView = NO; 283 | [self p_setDrawerPosition:[self p_postionToMoveFromPostion:self.currentPosition lastDragTargetContentOffSet:self.lastDragTargetContentOffSet scrollView:self.drawerScrollView supportedPosition:self.supportedPostions] animated:YES]; 284 | } 285 | } 286 | 287 | #pragma mark - AYDrawerScrollViewDelegate 288 | 289 | - (void)drawerScrollViewDidScroll:(UIScrollView *)scrollView { 290 | //当drawer中的scroll view 的contentOffset.y 为 0时,触发drawerScrollView滚动 291 | if (CGPointEqualToPoint(scrollView.contentOffset, CGPointZero)) { 292 | self.shouldScrollDrawerScrollView = YES; 293 | [scrollView setScrollEnabled:NO]; 294 | 295 | } else { 296 | self.shouldScrollDrawerScrollView = NO; 297 | [scrollView setScrollEnabled:YES]; 298 | } 299 | } 300 | 301 | #pragma mark - AYPassthroughScrollViewDelegate 302 | - (BOOL)shouldTouchPassthroughScrollView:(AYPassthroughScrollView *)scrollView 303 | point:(CGPoint)point { 304 | 305 | CGPoint p = [self.drawerContentContainer convertPoint:point fromView:scrollView]; 306 | return !CGRectContainsPoint(self.drawerContentContainer.bounds, p); 307 | } 308 | 309 | - (UIView *)viewToReceiveTouch:(AYPassthroughScrollView *)scrollView 310 | point:(CGPoint)point { 311 | if (self.currentPosition == AYPannelPositionOpen && self.backgroundDimmingView) { 312 | return self.backgroundDimmingView; 313 | } 314 | return self.primaryContentContainer; 315 | } 316 | 317 | 318 | #pragma mark - Getter and Setter 319 | - (void)setPrimaryContentViewController:(id)primaryContentViewController { 320 | 321 | if (!primaryContentViewController) { return; } 322 | _primaryContentViewController = primaryContentViewController; 323 | } 324 | 325 | - (void)setDrawerContentViewController:(id)drawerContentViewController { 326 | if (!drawerContentViewController) { return; } 327 | _drawerContentViewController = drawerContentViewController; 328 | } 329 | 330 | - (UIView *)drawerContentContainer { 331 | if (!_drawerContentContainer) { 332 | _drawerContentContainer = [[UIView alloc] initWithFrame:self.view.bounds]; 333 | _drawerContentContainer.backgroundColor = [UIColor clearColor]; 334 | } 335 | return _drawerContentContainer; 336 | } 337 | 338 | - (UIView *)drawerShadowView { 339 | if (!_drawerShadowView) { 340 | _drawerShadowView = [[UIView alloc] init]; 341 | } 342 | return _drawerShadowView; 343 | } 344 | 345 | - (UIView *)primaryContentContainer { 346 | if (!_primaryContentContainer) { 347 | _primaryContentContainer = [[UIView alloc] initWithFrame:self.view.bounds]; 348 | _primaryContentContainer.backgroundColor = [UIColor clearColor]; 349 | } 350 | return _primaryContentContainer; 351 | } 352 | 353 | - (AYPassthroughScrollView *)drawerScrollView { 354 | if (!_drawerScrollView) { 355 | _drawerScrollView = [[AYPassthroughScrollView alloc] initWithFrame:self.drawerContentContainer.bounds]; 356 | _drawerScrollView.delegate = self; 357 | } 358 | return _drawerScrollView; 359 | } 360 | 361 | - (UIView *)backgroundDimmingView { 362 | if (!_backgroundDimmingView) { 363 | if ([self.drawerContentViewController respondsToSelector:@selector(backgroundDimmingView)]) { 364 | _backgroundDimmingView = [self.drawerContentViewController backgroundDimmingView]; 365 | } 366 | [_backgroundDimmingView setUserInteractionEnabled:NO]; 367 | _backgroundDimmingView.alpha = 0.0; 368 | _tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(p_dimmingTapGestureRecognizer:)]; 369 | [_backgroundDimmingView addGestureRecognizer:_tapGestureRecognizer]; 370 | } 371 | return _backgroundDimmingView; 372 | } 373 | 374 | - (UIVisualEffectView *)drawerBackgroundVisualEffectView { 375 | if (!_drawerBackgroundVisualEffectView) { 376 | if ([self.drawerContentViewController respondsToSelector:@selector(drawerBackgroundVisualEffectView)]) { 377 | _drawerBackgroundVisualEffectView = [self.drawerContentViewController drawerBackgroundVisualEffectView]; 378 | } 379 | } 380 | return _drawerBackgroundVisualEffectView; 381 | } 382 | 383 | - (CGFloat)collapsedHeight { 384 | CGFloat collapsedHeight = kAYDefaultCollapsedHeight; 385 | 386 | if ([self.drawerContentViewController respondsToSelector:@selector(collapsedDrawerHeight)]) { 387 | collapsedHeight = [self.drawerContentViewController collapsedDrawerHeight]; 388 | } 389 | 390 | return collapsedHeight; 391 | } 392 | 393 | - (CGFloat)partialRevealDrawerHeight { 394 | CGFloat partialRevealDrawerHeight = kAYDefaultPartialRevealHeight; 395 | if ([self.drawerContentViewController respondsToSelector:@selector(partialRevealDrawerHeight)]) { 396 | partialRevealDrawerHeight = [self.drawerContentViewController partialRevealDrawerHeight]; 397 | } 398 | return partialRevealDrawerHeight; 399 | } 400 | 401 | - (void)setCurrentPosition:(AYPannelPosition)currentPosition { 402 | _currentPosition = currentPosition; 403 | //通知外部位置变化 404 | [_drawerContentViewController drawerPositionDidChange:self]; 405 | } 406 | 407 | - (NSSet *)supportedPostions { 408 | if (!_supportedPostions) { 409 | if ([_drawerContentViewController respondsToSelector:@selector(supportPannelPosition)]) { 410 | _supportedPostions = [_drawerContentViewController supportPannelPosition]; 411 | } 412 | if (!_supportedPostions) { //外层未返回,使用默认 413 | NSArray *array = @[@(AYPannelPositionOpen), @(AYPannelPositionClosed), @(AYPannelPositionCollapsed), @(AYPannelPositionPartiallyRevealed)]; 414 | _supportedPostions = [NSSet setWithArray:array]; 415 | } 416 | } 417 | return _supportedPostions; 418 | } 419 | 420 | #pragma mark - Private Mehtods 421 | 422 | - (void)p_maskBackgroundDimmingView { 423 | 424 | if (!self.backgroundDimmingView) { return; } 425 | 426 | CGFloat cornerRadius = [self p_cornerRadius]; 427 | CGFloat cutoutHeight = 2 * cornerRadius; 428 | CGFloat maskHeight = self.backgroundDimmingView.bounds.size.height - cutoutHeight - self.drawerScrollView.contentSize.height; 429 | CGFloat maskWidth = self.backgroundDimmingView.bounds.size.width; 430 | CGRect drawerRect = CGRectMake(0, maskHeight, maskWidth, self.drawerContentContainer.bounds.size.height); 431 | 432 | UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:drawerRect byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(cornerRadius, cornerRadius)]; 433 | CAShapeLayer *layer = [[CAShapeLayer alloc] init]; 434 | 435 | [path appendPath:[UIBezierPath bezierPathWithRect:self.backgroundDimmingView.bounds]]; 436 | [layer setFillRule:kCAFillRuleEvenOdd]; 437 | 438 | layer.path = path.CGPath; 439 | self.backgroundDimmingView.layer.mask = layer; 440 | } 441 | 442 | - (CGFloat)p_bottomSafeArea { 443 | CGFloat safeAreaBottomInset; 444 | if (@available(iOS 11.0, *)) { 445 | safeAreaBottomInset = self.view.safeAreaInsets.bottom; 446 | } else { 447 | safeAreaBottomInset = self.bottomLayoutGuide.length; 448 | } 449 | return safeAreaBottomInset; 450 | } 451 | 452 | - (void)p_dimmingTapGestureRecognizer:(UITapGestureRecognizer *)tapGesture { 453 | if (tapGesture == self.tapGestureRecognizer) { 454 | if (self.tapGestureRecognizer.state == UIGestureRecognizerStateEnded) { 455 | [self p_setDrawerPosition:AYPannelPositionCollapsed animated:YES]; 456 | } 457 | } 458 | } 459 | 460 | - (CGRect)p_backgroundDimmingViewFrameForDrawerPosition:(CGFloat)position { 461 | 462 | CGFloat cutoutHeight = 2 * [self p_cornerRadius]; 463 | CGRect backgroundDimmingViewFrame = self.backgroundDimmingView.frame; 464 | backgroundDimmingViewFrame.origin.y = 0 - position + cutoutHeight; 465 | return backgroundDimmingViewFrame; 466 | } 467 | 468 | - (AYPannelPosition)p_postionToMoveFromPostion:(AYPannelPosition)currentPosition 469 | lastDragTargetContentOffSet:(CGPoint)lastDragTargetContentOffSet 470 | scrollView:(UIScrollView *)scrollView 471 | supportedPosition:(NSSet *)supportedPosition { 472 | 473 | NSMutableArray *drawerStops = [[NSMutableArray alloc] init]; 474 | CGFloat currentDrawerPositionStop = 0.0f; 475 | 476 | if ([supportedPosition containsObject:@(AYPannelPositionCollapsed)]) { 477 | CGFloat collapsedHeight = [self collapsedHeight]; 478 | [drawerStops addObject:@(collapsedHeight)]; 479 | if (currentPosition == AYPannelPositionCollapsed) { 480 | currentDrawerPositionStop = collapsedHeight; 481 | } 482 | } 483 | 484 | if ([supportedPosition containsObject:@(AYPannelPositionPartiallyRevealed)]) { 485 | CGFloat partialHeight = [self partialRevealDrawerHeight]; 486 | [drawerStops addObject:@(partialHeight)]; 487 | if (currentPosition == AYPannelPositionPartiallyRevealed) { 488 | currentDrawerPositionStop = partialHeight; 489 | } 490 | } 491 | 492 | if ([supportedPosition containsObject:@(AYPannelPositionOpen)]) { 493 | CGFloat openHeight = scrollView.bounds.size.height; 494 | [drawerStops addObject:@(openHeight)]; 495 | if (currentPosition == AYPannelPositionOpen) { 496 | currentDrawerPositionStop = openHeight; 497 | } 498 | } 499 | 500 | //取最小值 501 | CGFloat lowestStop = [[drawerStops valueForKeyPath:@"@min.floatValue"] floatValue]; 502 | CGFloat distanceFromBottomOfView = lowestStop + lastDragTargetContentOffSet.y; 503 | CGFloat currentClosestStop = lowestStop; 504 | 505 | AYPannelPosition cloestValidDrawerPosition = currentPosition; 506 | 507 | for (NSNumber *currentStop in drawerStops) { 508 | if (fabs(currentStop.floatValue - distanceFromBottomOfView) < fabs(currentClosestStop - distanceFromBottomOfView)) { 509 | currentClosestStop = currentStop.integerValue; 510 | } 511 | } 512 | 513 | if (fabs(currentClosestStop - (scrollView.frame.size.height)) <= FLT_EPSILON && 514 | [supportedPosition containsObject:@(AYPannelPositionOpen)]) { 515 | 516 | cloestValidDrawerPosition = AYPannelPositionOpen; 517 | 518 | } else if (fabs(currentClosestStop - [self collapsedHeight]) <= FLT_EPSILON && 519 | [supportedPosition containsObject:@(AYPannelPositionCollapsed)]) { 520 | 521 | cloestValidDrawerPosition = AYPannelPositionCollapsed; 522 | 523 | } else if ([supportedPosition containsObject:@(AYPannelPositionPartiallyRevealed)]){ 524 | 525 | cloestValidDrawerPosition = AYPannelPositionPartiallyRevealed; 526 | 527 | } 528 | 529 | return cloestValidDrawerPosition; 530 | } 531 | 532 | - (void)p_setDrawerPosition:(AYPannelPosition)position 533 | animated:(BOOL)animated { 534 | 535 | if (![self.supportedPostions containsObject:@(position)]) { 536 | return; 537 | } 538 | 539 | CGFloat stopToMoveTo; 540 | CGFloat lowestStop = [self collapsedHeight]; 541 | if (position == AYPannelPositionCollapsed) { 542 | stopToMoveTo = lowestStop; 543 | } else if (position == AYPannelPositionPartiallyRevealed) { 544 | stopToMoveTo = [self partialRevealDrawerHeight]; 545 | } else if (position == AYPannelPositionOpen) { 546 | if (self.backgroundDimmingView) { 547 | stopToMoveTo = self.drawerScrollView.frame.size.height; 548 | } else { 549 | stopToMoveTo = self.drawerScrollView.frame.size.height - kAYDefaultShadowRadius; 550 | } 551 | } else { //close 552 | stopToMoveTo = 0.0f; 553 | } 554 | 555 | self.isAnimatingDrawerPosition = YES; 556 | self.currentPosition = position; 557 | 558 | __weak typeof (self) weakSelf = self; 559 | [UIView animateWithDuration:0.3 delay:0.0 usingSpringWithDamping:0.75 initialSpringVelocity:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 560 | [weakSelf.drawerScrollView setContentOffset:CGPointMake(0, stopToMoveTo - lowestStop) animated:NO]; 561 | 562 | if (weakSelf.backgroundDimmingView) { 563 | weakSelf.backgroundDimmingView.frame = [weakSelf p_backgroundDimmingViewFrameForDrawerPosition:stopToMoveTo]; 564 | } 565 | 566 | } completion:^(BOOL finished) { 567 | weakSelf.isAnimatingDrawerPosition = NO; 568 | }]; 569 | } 570 | 571 | - (BOOL)p_needsCornerRadius { 572 | return [self p_cornerRadius] > FLT_EPSILON; 573 | } 574 | 575 | - (CGFloat)p_cornerRadius { 576 | if ([self.drawerContentViewController respondsToSelector:@selector(drawerCornerRadius)]) { 577 | return [self.drawerContentViewController drawerCornerRadius]; 578 | } 579 | return 0.0f; 580 | } 581 | 582 | 583 | 584 | @end 585 | 586 | --------------------------------------------------------------------------------