2121
2222static 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