mark PopMenu · ljcode/Coding-iOS@893cf84 · GitHub
Skip to content

Commit 893cf84

Browse files
committed
mark PopMenu
1 parent 4bde8a5 commit 893cf84

11 files changed

Lines changed: 719 additions & 1 deletion

File tree

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 32 additions & 0 deletions
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// GlowImageView.h
3+
// JackFastKit
4+
//
5+
// Created by 曾 宪华 on 14-10-13.
6+
// Copyright (c) 2014年 华捷 iOS软件开发工程师 曾宪华. All rights reserved.
7+
//
8+
9+
// ==========================================
10+
// GlowImageView 菜单按钮 UIView 处理点击事件等
11+
// ==========================================
12+
13+
#import <UIKit/UIKit.h>
14+
15+
@interface GlowImageView : UIButton
16+
17+
/**
18+
* 设置阴影的偏移值(+,+)表示向左下偏移 默认为 (0,0)
19+
*/
20+
@property (nonatomic, assign) CGSize glowOffset;
21+
22+
/**
23+
* 设置阴影的模糊度 默认为: 5
24+
*/
25+
@property (nonatomic, assign) CGFloat glowAmount;
26+
27+
/**
28+
* 设置阴影的颜色 默认为 grayColor 灰色
29+
*/
30+
@property (nonatomic, strong) UIColor *glowColor;
31+
32+
@end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// GlowImageView.m
3+
// JackFastKit
4+
//
5+
// Created by 曾 宪华 on 14-10-13.
6+
// Copyright (c) 2014年 华捷 iOS软件开发工程师 曾宪华. All rights reserved.
7+
//
8+
9+
#import "GlowImageView.h"
10+
11+
12+
13+
@implementation GlowImageView
14+
15+
/**
16+
* 设置阴影的颜色
17+
*/
18+
- (void)setGlowColor:(UIColor *)newGlowColor {
19+
_glowColor = newGlowColor;
20+
if (newGlowColor) {
21+
[self setUpProperty];
22+
}
23+
}
24+
25+
- (instancetype)initWithFrame:(CGRect)frame {
26+
self = [super initWithFrame:frame];
27+
if (self) {
28+
29+
}
30+
return self;
31+
}
32+
33+
/**
34+
* 根据阴影 设置图层 默认属性
35+
*/
36+
- (void)setUpProperty {
37+
self.layer.shadowColor = self.glowColor.CGColor;
38+
self.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(-5, -5, CGRectGetWidth(self.bounds) + 10, CGRectGetHeight(self.bounds) + 10) cornerRadius:(CGRectGetHeight(self.bounds) + 10) / 2.0].CGPath;
39+
self.layer.shadowOffset = CGSizeMake(0.0, 0.0);
40+
self.layer.shadowOpacity = 0.5;
41+
self.layer.masksToBounds = NO;
42+
}
43+
44+
@end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// MenuButton.h
3+
// JackFastKit
4+
//
5+
// Created by 曾 宪华 on 14-10-13.
6+
// Copyright (c) 2014年 华捷 iOS软件开发工程师 曾宪华. All rights reserved.
7+
//
8+
9+
// ==========================================
10+
// MenuButton 菜单视图 UIView 处理点击事件等
11+
// ==========================================
12+
#import <UIKit/UIKit.h>
13+
14+
@class MenuItem;
15+
16+
typedef void(^DidSelctedItemCompletedBlock)(MenuItem *menuItem);
17+
18+
@interface MenuButton : UIView
19+
20+
/**
21+
* 点击操作
22+
*/
23+
@property (nonatomic, copy) DidSelctedItemCompletedBlock didSelctedItemCompleted;
24+
25+
#pragma mark - init
26+
- (instancetype)initWithFrame:(CGRect)frame menuItem:(MenuItem *)menuItem;
27+
28+
@end
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//
2+
// MenuButton.m
3+
// JackFastKit
4+
//
5+
// Created by 曾 宪华 on 14-10-13.
6+
// Copyright (c) 2014年 华捷 iOS软件开发工程师 曾宪华. All rights reserved.
7+
//
8+
9+
#import "MenuButton.h"
10+
#import <POP.h>
11+
12+
// Model
13+
#import "MenuItem.h"
14+
15+
// View
16+
#import "GlowImageView.h"
17+
18+
@interface MenuButton ()
19+
20+
@property (nonatomic, strong) GlowImageView *iconImageView;
21+
@property (nonatomic, strong) UILabel *titleLabel;
22+
23+
@property (nonatomic, strong) MenuItem *menuItem;
24+
25+
@end
26+
27+
@implementation MenuButton
28+
29+
- (instancetype)initWithFrame:(CGRect)frame menuItem:(MenuItem *)menuItem {
30+
self = [super initWithFrame:frame];
31+
if (self) {
32+
// Initialization code
33+
self.menuItem = menuItem;
34+
35+
self.iconImageView = [[GlowImageView alloc] initWithFrame:CGRectMake(0, 0, menuItem.iconImage.size.width, menuItem.iconImage.size.height)];
36+
self.iconImageView.userInteractionEnabled = NO;
37+
[self.iconImageView setImage:menuItem.iconImage forState:UIControlStateNormal];
38+
self.iconImageView.glowColor = menuItem.glowColor;
39+
self.iconImageView.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.iconImageView.bounds));
40+
[self addSubview:self.iconImageView];
41+
42+
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.iconImageView.frame), CGRectGetWidth(self.bounds), 35)];
43+
self.titleLabel.textColor = [UIColor whiteColor];
44+
self.titleLabel.backgroundColor = [UIColor clearColor];
45+
self.titleLabel.font = [UIFont systemFontOfSize:14];
46+
self.titleLabel.textAlignment = NSTextAlignmentCenter;
47+
self.titleLabel.text = menuItem.title;
48+
CGPoint center = self.titleLabel.center;
49+
center.x = CGRectGetMidX(self.bounds);
50+
self.titleLabel.center = center;
51+
[self addSubview:self.titleLabel];
52+
}
53+
return self;
54+
}
55+
56+
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
57+
// 播放缩放动画
58+
POPSpringAnimation *scaleAnimation = [POPSpringAnimation animation];
59+
scaleAnimation.springBounciness = 20; // value between 0-20
60+
scaleAnimation.springSpeed = 20; // value between 0-20
61+
scaleAnimation.property = [POPAnimatableProperty propertyWithName:kPOPViewScaleXY];
62+
scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(1.3, 1.3)];
63+
[self pop_addAnimation:scaleAnimation forKey:@"scaleAnimationKey"];
64+
}
65+
66+
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
67+
[self disMissCompleted:NULL];
68+
}
69+
70+
- (void)disMissCompleted:(void(^)(BOOL finished))completed {
71+
POPSpringAnimation *scaleAnimation = [POPSpringAnimation animation];
72+
scaleAnimation.springBounciness = 16; // value between 0-20
73+
scaleAnimation.springSpeed = 14; // value between 0-20
74+
scaleAnimation.property = [POPAnimatableProperty propertyWithName:kPOPViewScaleXY];
75+
scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(1.0, 1.0)];
76+
scaleAnimation.completionBlock = ^(POPAnimation *anim, BOOL finished) {
77+
if (completed) {
78+
completed(finished);
79+
}
80+
};
81+
[self pop_addAnimation:scaleAnimation forKey:@"scaleAnimationKey"];
82+
}
83+
84+
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
85+
// 回调
86+
[self disMissCompleted:^(BOOL finished) {
87+
if (self.didSelctedItemCompleted) {
88+
self.didSelctedItemCompleted(self.menuItem);
89+
}
90+
}];
91+
}
92+
93+
@end
Lines changed: 72 additions & 0 deletions

0 commit comments

Comments
 (0)