forked from lilei644/LLSlideMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLLSlideMenu.m
More file actions
212 lines (177 loc) · 5.88 KB
/
Copy pathLLSlideMenu.m
File metadata and controls
212 lines (177 loc) · 5.88 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//
// LLSideMune.m
// LLSideMenuDemo
//
// Created by admin on 15/11/20.
// Copyright © 2015年 LiLei. All rights reserved.
//
#import "LLSlideMenu.h"
#import "UIView+SetRect.h"
#import "LLDisplayLayer.h"
#import "LLCircleLayer.h"
#define LL_SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define LL_SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
@interface LLSlideMenu ()
// 菜单显示的View
@property (nonatomic, strong) UIView *displayView;
// 点击关闭菜单的Button
@property (nonatomic, strong) UIButton *closeMenuButton;
// displayLayer
@property (nonatomic, strong) LLDisplayLayer *displayLayer;
// circleLayer
@property (nonatomic, strong) LLCircleLayer *circleLayer;
@property (nonatomic, assign) BOOL isOverLoad;
@end
@implementation LLSlideMenu
//=====================
// 初始化
//=====================
- (instancetype)init {
self = [super initWithFrame:CGRectMake(0, 0, LL_SCREEN_WIDTH, LL_SCREEN_HEIGHT)];
if (self) {
[self initSetUpView];
}
return self;
}
//=====================
// 初始化界面
//=====================
- (void)initSetUpView {
_isOverLoad = NO;
[self.layer addSublayer:self.displayLayer];
_displayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, LL_SCREEN_HEIGHT)];
// _displayView.backgroundColor = [UIColor greenColor];
[self addSubview:self.displayView];
// 隐藏
self.hidden = YES;
// 动画管理
_ll_animManager = [LLAnimationManager new];
_ll_animManager.isAnimating = NO;
_ll_animManager.llSildeMenu = self;
_ll_animManager.circleLayer = _circleLayer;
_ll_isOpen = NO;
// 设置默认弹力大小和关键帧数量
_ll_animManager.springDamping = 20.f;
_ll_animManager.springVelocity = 15.f;
_ll_animManager.springNumOfFrames = 60;
}
//=====================
// 设置View宽度
//=====================
- (void)setLl_menuWidth:(CGFloat)ll_menuWidth {
_ll_menuWidth = ll_menuWidth;
_displayView.width = ll_menuWidth;
self.closeMenuButton.x = ll_menuWidth;
self.closeMenuButton.width = LL_SCREEN_WIDTH - ll_menuWidth;
self.displayLayer.bgWidth = ll_menuWidth;
_ll_animManager.layer = _displayLayer;
_ll_animManager.circleLayer = self.circleLayer;
}
//=====================
// 设置滑动偏移距离
//=====================
- (void)setLl_distance:(CGFloat)ll_distance {
_ll_distance = ll_distance;
self.hidden = NO;
self.displayLayer.distance = ll_distance;
_displayLayer.isAnimating = NO;
_ll_animManager.isAnimating = NO;
[_displayLayer setNeedsDisplay];
}
//=================================
// 添加menu背景色
//=================================
- (void)setLl_menuBackgroundColor:(UIColor *)ll_menuBackgroundColor {
_ll_menuBackgroundColor = ll_menuBackgroundColor;
_displayLayer.menuBgColor = ll_menuBackgroundColor;
}
//=================================
// 添加menu背景图片
//=================================
- (void)setLl_menuBackgroundImage:(UIImage *)ll_menuBackgroundImage {
_ll_menuBackgroundImage = ll_menuBackgroundImage;
_displayLayer.menuBgColor = [UIColor colorWithPatternImage:ll_menuBackgroundImage];
}
//=================================
// 设置弹力程度和关键帧数量
//=================================
- (void)setLl_springDamping:(CGFloat)ll_springDamping {
_ll_springDamping = ll_springDamping;
_ll_animManager.springDamping = ll_springDamping;
}
- (void)setLl_springVelocity:(CGFloat)ll_springVelocity {
_ll_springVelocity = ll_springVelocity;
_ll_animManager.springVelocity = ll_springVelocity;
}
- (void)setLl_springFramesNum:(NSInteger)ll_springFramesNum {
_ll_springFramesNum = ll_springFramesNum;
_ll_animManager.springNumOfFrames = ll_springFramesNum;
}
//=====================
// 关闭菜单
//=====================
- (void)ll_closeSlideMenu {
if (_ll_animManager.isAnimating) {
return;
}
_displayLayer.isAnimating = YES;
_closeMenuButton.hidden = YES;
_ll_animManager.isAnimating = YES;
[_ll_animManager endAnimate];
}
//=====================
// 打开菜单
//=====================
- (void)ll_openSlideMenu {
if (_ll_animManager.isAnimating) {
return;
}
self.hidden = NO;
_displayLayer.isAnimating = NO;
_closeMenuButton.hidden = NO;
_ll_animManager.isAnimating = YES;
[_ll_animManager startAnimate];
}
//=================================
// 添加View直接添加到displayView上
//=================================
- (void)addSubview:(UIView *)view {
if (view != _displayView && view != _closeMenuButton) {
[_displayView addSubview:view];
} else {
[super addSubview:view];
}
}
#pragma 懒加载
- (UIButton *)closeMenuButton {
if (!_closeMenuButton) {
_closeMenuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, LL_SCREEN_WIDTH, LL_SCREEN_HEIGHT)];
_closeMenuButton.hidden = YES;
[_closeMenuButton addTarget:self action:@selector(ll_closeSlideMenu) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_closeMenuButton];
}
return _closeMenuButton;
}
- (LLDisplayLayer *)displayLayer {
if (!_displayLayer) {
_displayLayer = [[LLDisplayLayer alloc] init];
[_displayLayer setFrame:CGRectMake(0, 0, LL_SCREEN_WIDTH, LL_SCREEN_HEIGHT)];
// layer添加阴影
_displayLayer.shadowOffset = CGSizeMake(0, 3);
_displayLayer.shadowRadius = 5.0;
_displayLayer.shadowColor = [UIColor blackColor].CGColor;
_displayLayer.shadowOpacity = 0.6;
}
return _displayLayer;
}
- (LLCircleLayer *)circleLayer {
if (!_circleLayer) {
_circleLayer = [[LLCircleLayer alloc] init];
[_circleLayer setFrame:CGRectMake(0, 0, _displayView.width, _displayView.height)];
_circleLayer.radius = 0;
_circleLayer.center = _displayView.center;
_displayView.layer.mask = self.circleLayer;
}
return _circleLayer;
}
@end