From 1b9752ff8162a806abf08275171d68593045e271 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 18 Jan 2015 20:16:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=80=E6=96=B0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E6=9B=B4=E5=BF=AB=E6=8D=B7=E7=9A=84=E5=AE=9A?= =?UTF-8?q?=E5=88=B6pop=E7=9A=84=E5=8A=A8=E6=84=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PopMenu.podspec | 2 +- PopMenu/PopMenu.h | 3 ++ PopMenu/PopMenu.m | 49 ++++++++++++++++--- .../PopMenuExample/ViewController.m | 3 ++ 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/PopMenu.podspec b/PopMenu.podspec index 89f5355..164de20 100644 --- a/PopMenu.podspec +++ b/PopMenu.podspec @@ -1,5 +1,5 @@ Pod::Spec.new do |s| - s.name = "PopMennu" + s.name = "PopMenu" s.version = "2.0" s.summary = "PopMenu is pop animation menu inspired by Sina weibo / NetEse app." s.homepage = "https://github.com/xhzengAIB/PopMenu" diff --git a/PopMenu/PopMenu.h b/PopMenu/PopMenu.h index 74962e5..32276c3 100644 --- a/PopMenu/PopMenu.h +++ b/PopMenu/PopMenu.h @@ -30,6 +30,9 @@ typedef void(^DidSelectedItemBlock)(MenuItem *selectedItem); items:(NSArray *)items; - (void)showMenuAtView:(UIView *)containerView; +- (void)showMenuAtView:(UIView *)containerView + startPoint:(CGPoint)startPoint + endPoint:(CGPoint)endPoint; - (void)dismissMenu; @end diff --git a/PopMenu/PopMenu.m b/PopMenu/PopMenu.m index 0578963..336cbfd 100644 --- a/PopMenu/PopMenu.m +++ b/PopMenu/PopMenu.m @@ -29,6 +29,9 @@ @interface PopMenu () @property (nonatomic, assign, readwrite) BOOL isShowed; +@property (nonatomic, assign) CGPoint startPoint; +@property (nonatomic, assign) CGPoint endPoint; + @end @implementation PopMenu @@ -77,9 +80,27 @@ - (void)setup { #pragma mark - 公开方法 - (void)showMenuAtView:(UIView *)containerView { + CGPoint startPoint = CGPointMake(0, CGRectGetHeight(self.bounds)); + CGPoint endPoint = startPoint; + switch (self.menuAnimationType) { + case kPopMenuAnimationTypeNetEase: + startPoint.x = CGRectGetMidX(self.bounds); + endPoint.x = startPoint.x; + break; + default: + break; + } + [self showMenuAtView:containerView startPoint:startPoint endPoint:endPoint]; +} + +- (void)showMenuAtView:(UIView *)containerView + startPoint:(CGPoint)startPoint + endPoint:(CGPoint)endPoint { if (self.isShowed) { return; } + self.startPoint = startPoint; + self.endPoint = endPoint; [containerView addSubview:self]; [self.realTimeBlur showBlurViewAtView:self]; } @@ -109,9 +130,17 @@ - (void)showButtons { CGRect toRect = [self getFrameWithItemCount:items.count perRowItemCount:perRowItemCount perColumItemCount:3 itemWidth:menuButtonWidth itemHeight:MenuButtonHeight paddingX:MenuButtonVerticalPadding paddingY:MenuButtonHorizontalMargin atIndex:index onPage:0]; CGRect fromRect = toRect; - fromRect.origin.y = CGRectGetHeight(self.bounds); - if (self.menuAnimationType == kPopMenuAnimationTypeNetEase) { - fromRect.origin.x = (CGRectGetWidth(self.bounds) - menuButtonWidth) / 2.0; + + switch (self.menuAnimationType) { + case kPopMenuAnimationTypeSina: + fromRect.origin.y = self.startPoint.y; + break; + case kPopMenuAnimationTypeNetEase: + fromRect.origin.x = self.startPoint.x - menuButtonWidth / 2.0; + fromRect.origin.y = self.startPoint.y; + break; + default: + break; } if (!menuButton) { menuButton = [[MenuButton alloc] initWithFrame:fromRect menuItem:menuItem]; @@ -140,9 +169,17 @@ - (void)hidenButtons { CGRect fromRect = menuButton.frame; CGRect toRect = fromRect; - toRect.origin.y = CGRectGetHeight(self.bounds); - if (self.menuAnimationType == kPopMenuAnimationTypeNetEase) { - toRect.origin.x = CGRectGetMidX(self.bounds) - CGRectGetMidX(menuButton.bounds); + + switch (self.menuAnimationType) { + case kPopMenuAnimationTypeSina: + toRect.origin.y = self.endPoint.y; + break; + case kPopMenuAnimationTypeNetEase: + toRect.origin.x = self.endPoint.x - CGRectGetMidX(menuButton.bounds); + toRect.origin.y = self.endPoint.y; + break; + default: + break; } double delayInSeconds = (items.count - index) * MenuButtonAnimationInterval; diff --git a/PopMenuExample/PopMenuExample/ViewController.m b/PopMenuExample/PopMenuExample/ViewController.m index a3630e4..abf56fc 100644 --- a/PopMenuExample/PopMenuExample/ViewController.m +++ b/PopMenuExample/PopMenuExample/ViewController.m @@ -58,7 +58,10 @@ - (void)showMenu { _popMenu.didSelectedItemCompletion = ^(MenuItem *selectedItem) { }; + [_popMenu showMenuAtView:self.view]; + +// [_popMenu showMenuAtView:self.view startPoint:CGPointMake(CGRectGetWidth(self.view.bounds) - 60, CGRectGetHeight(self.view.bounds)) endPoint:CGPointMake(60, CGRectGetHeight(self.view.bounds))]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {