forked from typeoneerror/GKAchievementNotification
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGKAchievementNotification.m
More file actions
executable file
·186 lines (157 loc) · 5.94 KB
/
GKAchievementNotification.m
File metadata and controls
executable file
·186 lines (157 loc) · 5.94 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//
// GKAchievementNotification.m
//
// Created by Benjamin Borowski on 9/30/10.
// Copyright 2010 Typeoneerror Studios. All rights reserved.
// $Id$
//
#import <GameKit/GameKit.h>
#import "GKAchievementNotification.h"
#pragma mark -
@interface GKAchievementNotification(private)
- (void)delegateCallback:(SEL)selector withObject:(id)object;
@end
#pragma mark -
@implementation GKAchievementNotification(private)
- (void)delegateCallback:(SEL)selector withObject:(id)object
{
if (self.handlerDelegate)
{
if ([self.handlerDelegate respondsToSelector:selector])
{
[self.handlerDelegate performSelector:selector withObject:object];
}
}
}
@end
#pragma mark -
@implementation GKAchievementNotification
@synthesize background=_background;
@synthesize handlerDelegate=_handlerDelegate;
@synthesize detailLabel=_detailLabel;
@synthesize logo=_logo;
@synthesize message=_message;
@synthesize title=_title;
@synthesize textLabel=_textLabel;
#pragma mark -
- (id)initWithTitle:(NSString *)title andMessage:(NSString *)message
{
CGRect frame = kGKAchievementDefaultSize;
self.title = title;
self.message = message;
[self initWithFrame:frame];
return self;
}
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
// create the GK background
UIImage *backgroundStretch = [[UIImage imageNamed:@"gk-notification.png"] stretchableImageWithLeftCapWidth:8.0f topCapHeight:0.0f];
UIImageView *tBackground = [[UIImageView alloc] initWithFrame:frame];
tBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth;
tBackground.image = backgroundStretch;
self.background = tBackground;
self.opaque = NO;
[tBackground release];
[self addSubview:self.background];
CGRect r1 = kGKAchievementText1;
CGRect r2 = kGKAchievementText2;
// create the text label
UILabel *tTextLabel = [[UILabel alloc] initWithFrame:r1];
tTextLabel.textAlignment = UITextAlignmentCenter;
tTextLabel.backgroundColor = [UIColor clearColor];
tTextLabel.textColor = [UIColor whiteColor];
tTextLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:15.0f];
tTextLabel.text = NSLocalizedString(@"Achievement Unlocked", @"Achievemnt Unlocked Message");
tTextLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.textLabel = tTextLabel;
[tTextLabel release];
// detail label
UILabel *tDetailLabel = [[UILabel alloc] initWithFrame:r2];
tDetailLabel.textAlignment = UITextAlignmentCenter;
tDetailLabel.adjustsFontSizeToFitWidth = YES;
tDetailLabel.minimumFontSize = 10.0f;
tDetailLabel.backgroundColor = [UIColor clearColor];
tDetailLabel.textColor = [UIColor whiteColor];
tDetailLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:11.0f];
tDetailLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.detailLabel = tDetailLabel;
[tDetailLabel release];
if (self.title)
{
self.textLabel.text = self.title;
}
if (self.message)
{
self.detailLabel.text = self.message;
}
[self addSubview:self.textLabel];
[self addSubview:self.detailLabel];
self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
}
return self;
}
- (void)dealloc
{
self.handlerDelegate = nil;
self.logo = nil;
self.message = nil;
self.title = nil;
self.detailLabel = nil;
self.textLabel = nil;
self.logo = nil;
self.background = nil;
[super dealloc];
}
#pragma mark -
-(void)animate {
[UIView animateWithDuration:kGKAchievementAnimeTime
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
[self delegateCallback:@selector(willShowAchievementNotification:) withObject:self];
self.frame = CGRectMake(self.frame.origin.x, 10.0f, self.frame.size.width, self.frame.size.height);
}
completion:^(BOOL finished){
[self delegateCallback:@selector(didShowAchievementNotification:) withObject:self];
[UIView animateWithDuration:kGKAchievementAnimeTime
delay:kGKAchievementDisplayTime
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
[self delegateCallback:@selector(willHideAchievementNotification:) withObject:self];
self.frame = CGRectMake(self.frame.origin.x , -53.0f, self.frame.size.width, self.frame.size.height);
}
completion:^(BOOL finished){
[self delegateCallback:@selector(didHideAchievementNotification:) withObject:self];
[self removeFromSuperview];
}];
}];
}
- (void)setImage:(UIImage *)image
{
if (image)
{
if (!self.logo)
{
UIImageView *tLogo = [[UIImageView alloc] initWithFrame:CGRectMake(7.0f, 6.0f, 34.0f, 34.0f)];
tLogo.contentMode = UIViewContentModeScaleAspectFit;
self.logo = tLogo;
[tLogo release];
[self addSubview:self.logo];
}
self.logo.image = image;
self.textLabel.frame = kGKAchievementText1WLogo;
self.detailLabel.frame = kGKAchievementText2WLogo;
}
else
{
if (self.logo)
{
[self.logo removeFromSuperview];
}
self.textLabel.frame = kGKAchievementText1;
self.detailLabel.frame = kGKAchievementText2;
}
}
@end