-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfileImageView.m
66 lines (59 loc) · 1.78 KB
/
ProfileImageView.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
//
// ProfileImageView.m
// unnamed
//
// Created by Bruce Ng on 2/20/15.
// Copyright (c) 2015 com.yahoo. All rights reserved.
//
#import "ProfileImageView.h"
#import "ProfileViewController.h"
#import "UIImageView+AFNetworking.h"
@implementation ProfileImageView
- (void) setup {
self.isEnabled = YES;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onImageTap:)];
[self setUserInteractionEnabled:YES];
[self addGestureRecognizer:tapGesture];
self.contentMode = UIViewContentModeScaleAspectFill;
self.layer.cornerRadius = self.frame.size.width/2;
self.clipsToBounds = YES;
}
- (void)setUser:(User *)user {
_user = user;
[self setImageWithURL:[NSURL URLWithString:user.profileImageUrl]];
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self setup];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (IBAction)onImageTap:(UITapGestureRecognizer *)sender {
if (self.isEnabled) {
[UIView animateWithDuration:0.2 animations:^{
self.transform = CGAffineTransformMakeScale(1.1, 1.1);
} completion:^(BOOL finished) {
[self.delegate profileImageView:self tappedUser:self.user];
[UIView animateWithDuration:0.2 animations:^{
self.transform = CGAffineTransformMakeScale(1.0, 1.0);
} completion:^(BOOL finished) {
}];
}];
}
}
@end