Skip to content

Commit 1f23078

Browse files
committed
Modified heirarchy of Thumbnail
1 parent 98a93a0 commit 1f23078

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

VCThumbnailGridView/VCThumbnailButton.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
#import "VCResponseFetcher.h"
1212

13-
@interface VCThumbnailButton : UIButton <VCResponseFetchServiceDelegate> {
13+
@interface VCThumbnailButton : UIView <VCResponseFetchServiceDelegate> {
14+
UIButton *imageButton;
1415
UIActivityIndicatorView *activityIndicator;
1516
UIImageView *selectedIndicatorImageView;
1617
BOOL shouldShowActivityIndicator;

VCThumbnailGridView/VCThumbnailButton.m

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,21 @@ - (id)initWithFrame:(CGRect)frame {
2929
self.userInteractionEnabled = NO;
3030
self.contentMode = UIViewContentModeScaleAspectFit;
3131

32+
imageButton = [[UIButton alloc] initWithFrame:CGRectZero];
33+
[imageButton addTarget:self action:@selector(didTapSelf:) forControlEvents:UIControlEventTouchUpInside];
34+
[self addSubview:imageButton];
35+
3236
selectedIndicatorImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
37+
selectedIndicatorImageView.alpha = 0.0;
3338
selectedIndicatorImageView.image = [UIImage imageNamed:@"check.png"];
3439
[selectedIndicatorImageView sizeToFit];
35-
selectedIndicatorImageView.hidden = YES;
36-
[self addSubview:selectedIndicatorImageView];
37-
38-
[self addTarget:self action:@selector(didTapSelf:) forControlEvents:UIControlEventTouchUpInside];
40+
[self addSubview:selectedIndicatorImageView];
3941
}
4042
return self;
4143
}
4244

4345
- (void)dealloc {
46+
[imageButton release];
4447
[selectedIndicatorImageView release];
4548
[activityIndicator release];
4649
[super dealloc];
@@ -49,6 +52,7 @@ - (void)dealloc {
4952
- (void)layoutSubviews {
5053
[super layoutSubviews];
5154

55+
imageButton.frame = self.bounds;
5256
activityIndicator.frame = CGRectMake((self.bounds.size.width - activityIndicator.bounds.size.width)/2,
5357
(self.bounds.size.height - activityIndicator.bounds.size.height)/2,
5458
activityIndicator.bounds.size.width,
@@ -81,8 +85,8 @@ - (void)didTapSelf:(id)sender {
8185
#pragma mark - Public Methods
8286

8387
- (void)setImage:(UIImage*)image {
84-
[self setBackgroundImage:image
85-
forState:UIControlStateNormal];
88+
[imageButton setBackgroundImage:image
89+
forState:UIControlStateNormal];
8690
}
8791

8892
- (void)setImageUrl:(NSString*)url {
@@ -119,35 +123,49 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated
119123
NSLog(@"Index:%i selected:%i", self.tag, selected);
120124
#endif
121125

122-
selectedIndicatorImageView.hidden = !isSelected;
123-
}
124-
125-
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
126-
{
127-
isEditing = editing;
128-
129126
if (animated) [UIView beginAnimations:nil context:nil];
130127

131-
if (isEditing)
128+
if (isSelected)
132129
{
133-
self.alpha = 0.8;
134-
}else
130+
selectedIndicatorImageView.alpha = 1.0;
131+
imageButton.alpha = 0.8;
132+
}
133+
else
135134
{
136-
self.alpha = 1.0;
135+
selectedIndicatorImageView.alpha = 0.0;
136+
imageButton.alpha = 1.0;
137137
}
138-
139138
if (animated) [UIView commitAnimations];
140-
141-
[self setSelected:NO animated:YES];
139+
}
140+
141+
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
142+
{
143+
if (isEditing != editing) {
144+
isEditing = editing;
145+
146+
if (animated) [UIView beginAnimations:nil context:nil];
147+
148+
// if (isEditing)
149+
// {
150+
// imageButton.alpha = 0.8;
151+
// }else
152+
// {
153+
// imageButton.alpha = 1.0;
154+
// }
155+
156+
if (animated) [UIView commitAnimations];
157+
158+
[self setSelected:NO animated:YES];
159+
}
142160
}
143161

144162
#pragma mark - VCResponseFetchServiceDelegate Methods
145163

146164
-(void)didSucceedReceiveResponse:(NSObject<VCDataProcessorDelegate> *)response {
147165
if ([response isKindOfClass:[VCImageResponseProcessor class]]) {
148166
UIImage *image = [(VCImageResponseProcessor*)response image];
149-
[self setBackgroundImage:image
150-
forState:UIControlStateNormal];
167+
[imageButton setBackgroundImage:image
168+
forState:UIControlStateNormal];
151169

152170
}
153171
}

0 commit comments

Comments
 (0)