Skip to content

Commit c1ff95d

Browse files
committed
fix code
1 parent 0f53965 commit c1ff95d

File tree

6 files changed

+41
-44
lines changed

6 files changed

+41
-44
lines changed

Example/MLMenu/MLViewController.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ - (void)testCode_One
6262
menuView.didSelectBlock = ^(NSInteger index) {
6363
NSLog(@"%zd",index);
6464
};
65-
[menuView showMenuEnterAnimation:MLEnterAnimationStyleNone];
65+
[menuView showMenuEnterAnimation:MLAnimationStyleNone];
6666

6767
}
6868

@@ -75,7 +75,7 @@ - (void)testCode_Two
7575
menuView.didSelectBlock = ^(NSInteger index) {
7676
NSLog(@"%zd",index);
7777
};
78-
[menuView showMenuEnterAnimation:MLEnterAnimationStyleNone];
78+
[menuView showMenuEnterAnimation:MLAnimationStyleNone];
7979
}
8080

8181

@@ -87,7 +87,7 @@ - (void)testCode_Three
8787
menuView.didSelectBlock = ^(NSInteger index) {
8888
NSLog(@"%zd",index);
8989
};
90-
[menuView showMenuEnterAnimation:MLEnterAnimationStyleRight];
90+
[menuView showMenuEnterAnimation:MLAnimationStyleTop];
9191
}
9292

9393
- (void)testCode_Four
@@ -100,7 +100,7 @@ - (void)testCode_Four
100100
menuView.didSelectBlock = ^(NSInteger index) {
101101
NSLog(@"%zd",index);
102102
};
103-
[menuView showMenuEnterAnimation:MLEnterAnimationStyleTop];
103+
[menuView showMenuEnterAnimation:MLAnimationStyleRight];
104104
}
105105

106106
- (void)testCode_Five
@@ -115,7 +115,7 @@ - (void)testCode_Five
115115
menuView.didSelectBlock = ^(NSInteger index) {
116116
NSLog(@"%zd",index);
117117
};
118-
[menuView showMenuEnterAnimation:MLEnterAnimationStyleNone];
118+
[menuView showMenuEnterAnimation:MLAnimationStyleTop];
119119
}
120120
- (void)testCode_Six
121121
{

MLMenu.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'MLMenu'
11-
s.version = '1.0.0'
11+
s.version = '1.0.1'
1212
s.summary = 'A Simple MLMenu.'
1313

1414
# This description is used to generate tags and improve search results.

MLMenu/Classes/MLMenuItemsView.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#import <UIKit/UIKit.h>
99
@class MLMenuItemsView;
1010
@protocol MLMenuItemsViewDelegate <NSObject>
11-
- (void)menuItemsView:(MLMenuItemsView *)itemView DidSelectItemAtIndex:(NSInteger)index;
11+
- (void)menuItemsView:(MLMenuItemsView *)itemView didSelectItemAtIndex:(NSInteger)index;
1212
@end
1313
@interface MLMenuItemsView : UIView
1414
@property (nonatomic, copy) void (^menuDidSelectBlock)(NSInteger index);
@@ -27,7 +27,7 @@
2727

2828
@class MLMenuItemView;
2929
@protocol MLMenuItemViewDelegate <NSObject>
30-
- (void)menuItemView:(MLMenuItemView *)itemView DidSelectItemAtIndex:(NSInteger)index;
30+
- (void)menuItemView:(MLMenuItemView *)itemView didSelectItemAtIndex:(NSInteger)index;
3131
@end
3232

3333
@interface MLMenuItemView : UIView

MLMenu/Classes/MLMenuItemsView.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ - (void)setContentColor:(UIColor *)contentColor{
126126
self.backgroundColor = _contentColor;
127127
}
128128

129-
- (void)menuItemView:(MLMenuItemView *)itemView DidSelectItemAtIndex:(NSInteger)index{
129+
- (void)menuItemView:(MLMenuItemView *)itemView didSelectItemAtIndex:(NSInteger)index{
130130

131-
if ([_delegate respondsToSelector:@selector(menuItemsView:DidSelectItemAtIndex:)]) {
132-
[_delegate menuItemsView:self DidSelectItemAtIndex:index];
131+
if ([_delegate respondsToSelector:@selector(menuItemsView:didSelectItemAtIndex:)]) {
132+
[_delegate menuItemsView:self didSelectItemAtIndex:index];
133133
}
134134
if (_menuDidSelectBlock) {
135135
_menuDidSelectBlock(index);
@@ -190,8 +190,8 @@ - (void)initialize:(NSInteger)index{
190190
}
191191

192192
- (void)itemAction:(MLButton *)sender{
193-
if ([_delegate respondsToSelector:@selector(menuItemView:DidSelectItemAtIndex:)]) {
194-
[_delegate menuItemView:self DidSelectItemAtIndex:sender.tag];
193+
if ([_delegate respondsToSelector:@selector(menuItemView:didSelectItemAtIndex:)]) {
194+
[_delegate menuItemView:self didSelectItemAtIndex:sender.tag];
195195
}
196196
}
197197

@@ -278,7 +278,7 @@ - (void)drawRect:(CGRect)rect{
278278
- (void)drawRectLine:(UIColor *)color{
279279
CGContextRef contextRef = UIGraphicsGetCurrentContext();
280280
CGMutablePathRef path = CGPathCreateMutable();
281-
CGContextSetLineWidth(contextRef, 0.5);
281+
CGContextSetLineWidth(contextRef, 1);
282282
[self.lineCustomeColor setStroke];
283283
CGPathMoveToPoint(path, NULL, 0, 1);
284284
CGPathAddLineToPoint(path, NULL, self.bounds.size.width, 1);

MLMenu/Classes/MLMenuView.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
@class MLMenuView;
1313

1414
@protocol MLMenuViewDelegate <NSObject>
15-
- (void)menuView:(MLMenuView *)menu DidselectItemIndex:(NSInteger)index;
15+
- (void)menuView:(MLMenuView *)menu didselectItemIndex:(NSInteger)index;
1616
@end
1717

18-
typedef NS_ENUM(NSInteger,MLEnterAnimationStyle) {
19-
MLEnterAnimationStyleNone,
20-
MLEnterAnimationStyleRight,
21-
MLEnterAnimationStyleTop,
18+
typedef NS_ENUM(NSInteger,MLAnimationStyle) {
19+
MLAnimationStyleNone,
20+
MLAnimationStyleRight,
21+
MLAnimationStyleTop,
2222
};
2323

2424
typedef void(^menuDidSelectBlock)(NSInteger index);
@@ -120,11 +120,11 @@ typedef void(^menuDidSelectBlock)(NSInteger index);
120120
/**
121121
呈现菜单
122122
*/
123-
- (void)showMenuEnterAnimation:(MLEnterAnimationStyle)animationStyle;
123+
- (void)showMenuEnterAnimation:(MLAnimationStyle)animationStyle;
124124

125125
/**
126126
隐藏菜单
127127
*/
128-
- (void)hidMenuExitAnimation:(MLEnterAnimationStyle)animationStyle;
128+
- (void)hidMenuExitAnimation:(MLAnimationStyle)animationStyle;
129129

130130
@end

MLMenu/Classes/MLMenuView.m

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
static NSString * const IDETIFIRE = @"MLMENUCELLIDETIFIRE";
2323

24-
@interface MLMenuView ()<UIGestureRecognizerDelegate>{
24+
@interface MLMenuView ()<UIGestureRecognizerDelegate,MLMenuItemsViewDelegate>{
2525
CGRect _frame;
2626
CGFloat _triangleOffsetLeft;
2727
CGFloat _menuViewOffsetTop;
2828
BOOL _isHasTriangle;
29-
MLEnterAnimationStyle _animationStyle;
29+
MLAnimationStyle _animationStyle;
3030
UIColor *_triangleColor;
3131
}
3232
@property (nonatomic, strong) UIView *coverView;
@@ -152,32 +152,28 @@ - (void)layoutSubviews
152152
frameItemsView.size.width = self.contentView.frame.size.width;
153153
frameItemsView.size.height = _isHasTriangle? self.contentView.frame.size.height - 10 : self.contentView.frame.size.height;
154154
self.itemsView.frame = frameItemsView;
155-
__weak typeof(self)WeakSelf = self;
156-
self.itemsView.menuDidSelectBlock = ^(NSInteger index) {
157-
if ([WeakSelf.delegate respondsToSelector:@selector(menuView:DidselectItemIndex:)]) {
158-
[WeakSelf.delegate menuView:WeakSelf DidselectItemIndex:index];
159-
}
160-
if (WeakSelf.didSelectBlock) {
161-
WeakSelf.didSelectBlock(index);
162-
}
163-
164-
};
165-
166-
167-
155+
168156
}
169157

170158

159+
#pragma mark MLMenuItemsViewDelegate
160+
- (void)menuItemsView:(MLMenuItemsView *)itemView didSelectItemAtIndex:(NSInteger)index{
161+
if ([self.delegate respondsToSelector:@selector(menuView:didselectItemIndex:)]) {
162+
[self.delegate menuView:self didselectItemIndex:index];
163+
}
164+
if (self.didSelectBlock) {
165+
self.didSelectBlock(index);
166+
}
167+
[self hidMenuExitAnimation:_animationStyle];
168+
}
171169

172170

173-
174-
175-
- (void)showMenuEnterAnimation:(MLEnterAnimationStyle)animationStyle
171+
- (void)showMenuEnterAnimation:(MLAnimationStyle)animationStyle
176172
{
177173

178174
_animationStyle = animationStyle;
179175
[self setSubViews];
180-
if (animationStyle == MLEnterAnimationStyleRight) {
176+
if (animationStyle == MLAnimationStyleRight) {
181177
self.contentView.layer.position = CGPointMake(_frame.origin.x + _frame.size.width, 0);
182178
self.contentView.layer.anchorPoint = CGPointMake(1, 0);
183179
self.contentView.clipsToBounds = YES;
@@ -187,7 +183,7 @@ - (void)showMenuEnterAnimation:(MLEnterAnimationStyle)animationStyle
187183
self.contentView.alpha = 1;
188184
self.contentView.transform = CGAffineTransformMakeScale(1, 1);
189185
}];
190-
}else if (animationStyle == MLEnterAnimationStyleTop){
186+
}else if (animationStyle == MLAnimationStyleTop){
191187
self.contentView.layer.position = CGPointMake(_frame.origin.x + _frame.size.width * 0.5, _menuViewOffsetTop);
192188
self.contentView.layer.anchorPoint = CGPointMake(0.5, 0);
193189
self.contentView.clipsToBounds = YES;
@@ -210,18 +206,18 @@ - (void)showMenuEnterAnimation:(MLEnterAnimationStyle)animationStyle
210206
}
211207

212208

213-
- (void)hidMenuExitAnimation:(MLEnterAnimationStyle)animationStyle
209+
- (void)hidMenuExitAnimation:(MLAnimationStyle)animationStyle
214210
{
215211

216-
if (_animationStyle == MLEnterAnimationStyleRight) {
212+
if (_animationStyle == MLAnimationStyleRight) {
217213
self.contentView.alpha = 1;
218214
[UIView animateWithDuration:0.2 animations:^{
219215
self.contentView.alpha = 0;
220216
self.contentView.transform = CGAffineTransformMakeScale(0.5, 0.5);
221217
} completion:^(BOOL finished) {
222218
[self removeFromSuperview];
223219
}];
224-
}else if (_animationStyle == MLEnterAnimationStyleTop){
220+
}else if (_animationStyle == MLAnimationStyleTop){
225221
self.contentView.transform = CGAffineTransformMakeScale(1, 1);
226222
[UIView animateWithDuration:0.2 animations:^{
227223
self.contentView.transform = CGAffineTransformMakeScale(1, 0.001);
@@ -288,6 +284,7 @@ - (MLMenuItemsView *)itemsView
288284
if (!_itemsView) {
289285
_itemsView = [[MLMenuItemsView alloc] initWiithMenuItemTitles:self.titles ImageNames:self.imageNames];
290286
_itemsView.backgroundColor = [UIColor colorWithRed:73/255.0 green:72/255.0 blue:75/255.0 alpha:1];
287+
_itemsView.delegate = self;
291288
}
292289
return _itemsView;
293290
}

0 commit comments

Comments
 (0)