-
Notifications
You must be signed in to change notification settings - Fork 0
/
QSHDRButton.m
70 lines (60 loc) · 1.79 KB
/
QSHDRButton.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
#import "QSHDRButton.h"
#import "QSConstants.h"
@protocol CAMHDRButtonDelegate <NSObject>
- (void)HDRButtonDidCollapse:(CAMHDRButton *)button;
- (void)HDRButtonWillExpand:(CAMHDRButton *)button;
- (void)HDRButtonWasPressed:(CAMHDRButton *)button;
- (void)HDRButtonModeDidChange:(CAMHDRButton *)button;
@end
@interface CAMHDRButton (SevenPointOne)
@property (nonatomic, assign) id <CAMHDRButtonDelegate> delegate;
@property (nonatomic, assign) NSInteger HDRMode;
@property (nonatomic, getter=isAutoDisallowed) NSInteger autoDisallowed;
- (void)setHDRMode:(NSInteger)mode notifyDelegate:(BOOL)notify;
@end
@interface QSHDRButton () <CAMHDRButtonDelegate>
{
id _target;
SEL _sel;
}
@end
@implementation QSHDRButton
- (instancetype)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
if ([self respondsToSelector:@selector(setDelegate:)]) {
self.delegate = self;
self.autoDisallowed = 1;
}
}
return self;
}
- (BOOL)isOn
{
return (self.HDRMode > 0);
}
- (void)setOn:(BOOL)on
{
if ([self respondsToSelector:@selector(setHDRMode:)]) {
self.HDRMode = (on ? 1 : 0);
[self setHDRMode:(on ? 1 : 0) notifyDelegate:YES];
}
else {
[super setOn:on];
}
}
- (void)setTapTarget:(id)target selector:(SEL)selector
{
[self removeTarget:_target action:_sel forControlEvents:UIControlEventTouchUpInside];
[self addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
_target = target;
_sel = selector;
}
- (void)HDRButtonDidCollapse:(CAMHDRButton *)button {}
- (void)HDRButtonWillExpand:(CAMHDRButton *)button {}
- (void)HDRButtonWasPressed:(CAMHDRButton *)button {}
- (void)HDRButtonModeDidChange:(CAMHDRButton *)button
{
[_target performSelector:_sel withObject:self];
}
@end