iOS抽屉效果和侧边菜单
来源:互联网 发布:方舟生存进化淘宝价格 编辑:程序博客网 时间:2024/05/02 06:46
iOS抽屉效果和侧边菜单
源码下载地址
1、效果演示
1. 抽屉效果演示
1. 侧边菜单演示
2、使用说明
构造方法 initialization
/// 构造方法(左控制器 & 右控制器 & 背景图片)-(instancetype)initWithLeftController:(UIViewController *)leftController andMainController:(UIViewController *)mainController andRightController:(UIViewController *)rightController andBackgroundImage:(UIImage *)image;/// 构造方法(左控制器 & 右控制器)-(instancetype)initWithLeftController:(UIViewController *)leftController andMainController:(UIViewController *)mainController andRightController:(UIViewController *)rightController;/// 构造方法(左控制器 & 右控制器)-(instancetype)initWithLeftController:(UIViewController *)leftController andMainView:(UIViewController *)mainController;/// 构造方法(右控制器)-(instancetype)initWithRightView:(UIViewController *)rightController andMainView:(UIViewController *)mainController;
视图控制方法 View control method
/// 恢复位置-(void)showMainView;/// 显示左视图-(void)showLeftView;/// 显示右视图-(void)showRighView;
属性 attribute
/// 主视图隐藏后显示比例(0~1)@property (nonatomic, assign) CGFloat otherScale;/// 主视图比例 (0~1)@property (nonatomic, assign) CGFloat mainScale;/// 滑动速度系数-建议在0.5-1之间。默认为0.5@property (assign,nonatomic) CGFloat speedf;/// 是否允许点击视图恢复视图位置。默认为yes@property (strong) UITapGestureRecognizer *sideslipTapGes;
3、使用方法
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 1. 创建window self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; // 2. 创建控制器 MainController *main = [[MainController alloc] init]; LeftController *left = [[LeftController alloc] init]; RightController *right = [[RightController alloc] init]; // 3. 创建跟控制器 JRMenuController *controller = [[JRMenuController alloc] initWithLeftController:left andMainController:main andRightController:right]; controller.mainScale = 0.8; controller.otherScale = 0.6; controller.speedf = 0.6; // 4. 设置跟控制器 self.window.rootViewController = controller; // 5. 显示 window [self.window makeKeyAndVisible]; return YES;}
4、 知识点总结
1. 滑动手势方向判断
// 滑动方向typedef NS_ENUM(NSInteger, CameraMoveDirection) { kCameraMoveDirectionNone, kCameraMoveDirectionUp, kCameraMoveDirectionDown, kCameraMoveDirectionRight, kCameraMoveDirectionLeft,};
//创建滑动手势 UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipe:)];
#pragma mark - 判断滑动方向- ( void )handleSwipe:( UIPanGestureRecognizer *)gesture { CGPoint translation = [gesture translationInView: self.view]; if (gesture.state == UIGestureRecognizerStateBegan ) { self.direction = kCameraMoveDirectionNone; } else if (gesture.state == UIGestureRecognizerStateChanged && self.direction == kCameraMoveDirectionNone) { // 获取 方向 self.direction = [ self determineCameraDirectionIfNeeded:translation]; } if (self.direction == kCameraMoveDirectionRight && self.leftControl != nil) { [self handlePan:gesture]; } if (self.direction == kCameraMoveDirectionLeft && self.righControl != nil) { [self handlePan:gesture]; }}
// 获取方向- ( CameraMoveDirection )determineCameraDirectionIfNeeded:( CGPoint )translation{ if (self.direction != kCameraMoveDirectionNone) return self.direction; if (fabs(translation.x) > gestureMinimumTranslation) { BOOL gestureHorizontal = NO; if (translation.y == 0.0 ) gestureHorizontal = YES; else gestureHorizontal = (fabs(translation.x / translation.y) > 5.0 ); if (gestureHorizontal) { if (translation.x > 0.0 ) return kCameraMoveDirectionRight; else return kCameraMoveDirectionLeft; } } else if (fabs(translation.y) > gestureMinimumTranslation) { BOOL gestureVertical = NO; if (translation.x == 0.0 ) gestureVertical = YES; else gestureVertical = (fabs(translation.y / translation.x) > 5.0 ); if (gestureVertical) { if (translation.y > 0.0 ) return kCameraMoveDirectionDown; else return kCameraMoveDirectionUp; } } return self.direction;}
2. 滑动手势和tableview滑动共存
#pragma mark - UIGestureRecognizerDelegate// 设置手势 滑动 和 tableView 滚动并存- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { if ([otherGestureRecognizer.view isKindOfClass:[UITableView class]]) { return YES; } return NO;}
3. tableviewcell 分割线设置贯穿整个tableView(补充)
// cell 行分割线 设置- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset: UIEdgeInsetsZero]; } if ([cell respondsToSelector:@selector(setLayoutManager:)]) { [cell setLayoutMargins:UIEdgeInsetsZero]; }}- (void)viewDidLayoutSubviews { if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)]; } if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)]; }}
1 0
- iOS抽屉效果和侧边菜单
- 抽屉效果侧边栏
- HorizontalScrollView+viewpager实现仿天天动听ios版和QQ侧边菜单效果
- Toolbar+DrawerLayout实现知乎app抽屉菜单侧边拉出并带有箭头动画效果
- 使用mmenu制作侧边抽屉菜单
- iOS抽屉效果、二级菜单(点击,拖拽滑动)
- ios侧边栏效果
- [iOS 抽屉DDMenuController] 侧边弹出库 使用
- IOS 简单抽屉效果
- iOS抽屉效果
- IOS 抽屉效果
- ios 抽屉效果实现
- iOS中的抽屉效果
- iOS中的抽屉效果
- iOS实现抽屉效果
- iOS抽屉效果
- IOS-抽屉效果
- iOS 抽屉效果实现
- FaceBook/infer-分析Android项目
- MySQL 主主同步配置步骤
- _int64 C语言中怎么用
- Redis主从自动failover
- C51中的数据类型
- iOS抽屉效果和侧边菜单
- redis 主从配制及手动切换
- C语言中通过按位与求奇偶源码
- 【4】天然气泄漏
- 【leetcode c++】14Longest Common Prefix
- 【iOS开发-网络】大文件的断点续传(断点下载)
- PHP压缩上传图片
- #leetcode#Jump Game II
- 屏蔽无耻的百度广告