Skip to content

Commit

Permalink
添加最新功能,更快捷的定制pop的动感
Browse files Browse the repository at this point in the history
  • Loading branch information
xhzengAIB committed Jan 18, 2015
1 parent 607e4a1 commit 1b9752f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
2 changes: 1 addition & 1 deletion PopMenu.podspec
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 3 additions & 0 deletions PopMenu/PopMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
49 changes: 43 additions & 6 deletions PopMenu/PopMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions PopMenuExample/PopMenuExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1b9752f

Please sign in to comment.