forked from bvogelzang/BounceMenuController
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlusButton.m
75 lines (58 loc) · 2.85 KB
/
PlusButton.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// PlusButton.m
// BounceExample
//
// Created by Benjamin Vogelzang on 9/25/13.
// Copyright (c) 2013 Ben Vogelzang. All rights reserved.
//
#import "PlusButton.h"
@interface PlusButton ()
@property (nonatomic, retain) UIView *verticalView;
@property (nonatomic, retain) UIView *horizontalView;
@end
@implementation PlusButton
@synthesize color;
@synthesize verticalView;
@synthesize horizontalView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSInteger lineWeight = 4;
self.horizontalView = [[UIView alloc] initWithFrame:CGRectMake(0, (frame.size.height * 0.5) - (lineWeight * 0.5), frame.size.width, lineWeight)];
self.horizontalView.backgroundColor = [UIColor whiteColor];
self.horizontalView.userInteractionEnabled = NO;
[self addSubview:self.horizontalView];
self.verticalView = [[UIView alloc] initWithFrame:CGRectMake((frame.size.width * 0.5) - (lineWeight * 0.5), 0, lineWeight, frame.size.height)];
self.verticalView.backgroundColor = [UIColor whiteColor];
self.verticalView.userInteractionEnabled = NO;
[self addSubview:self.verticalView];
}
return self;
}
- (void)setColor:(UIColor *)theColor {
color = theColor;
self.horizontalView.backgroundColor = theColor;
self.verticalView.backgroundColor = theColor;
}
- (void)showClose {
[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.verticalView.frame = CGRectMake(self.verticalView.frame.origin.x, self.frame.size.height * 0.5, self.verticalView.frame.size.width, 0);
self.horizontalView.frame = CGRectMake(-5, self.horizontalView.frame.origin.y, self.frame.size.width + 10, self.horizontalView.frame.size.height);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.horizontalView.frame = CGRectMake(0, self.horizontalView.frame.origin.y, self.frame.size.width, self.horizontalView.frame.size.height);
} completion:nil];
}];
}
- (void)showOpen {
[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.verticalView.frame = CGRectMake(self.verticalView.frame.origin.x, 0, self.verticalView.frame.size.width, self.frame.size.height);
self.horizontalView.frame = CGRectMake(5, self.horizontalView.frame.origin.y, self.frame.size.width - 10, self.horizontalView.frame.size.height);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.horizontalView.frame = CGRectMake(0, self.horizontalView.frame.origin.y, self.frame.size.width, self.horizontalView.frame.size.height);
} completion:nil];
}];
}
@end