forked from ZavenArra/SignatureView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSignatureViewController.m
77 lines (63 loc) · 1.8 KB
/
SignatureViewController.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
76
77
//
// SignatureViewController.m
//
// Created by John Montiel on 5/11/12.
//
#import "SignatureViewController.h"
@interface SignatureViewController ()
@property (strong, nonatomic) NSData *signature;
@end
@implementation SignatureViewController
@synthesize delegate;
@synthesize signatureTextField;
@synthesize view;
@synthesize signature;
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(beganSignature:) name:kBeganSignature object:self.view];
}
- (void)viewDidUnload
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:kBeganSignature object:self.view];
[self setView:nil];
[self setSignatureTextField:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (IBAction)signatureClearTapped:(id)sender
{
[self.view erase];
[UIView animateWithDuration:0.6 animations:^
{
[self.signatureTextField setAlpha:1.0];
}];
}
- (IBAction)signatureSignTapped:(id)sender
{
[self checkSign];
}
-(void)checkSign
{
if ((self.signature = UIImagePNGRepresentation([self.view getSignatureImage]))) {
[self.delegate signatureViewController:self didSign:self.signature signatureName:@"assessor"];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Signature" message:@"Please sign" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
- (void)beganSignature:(NSNotification *)notification
{
if ([notification object] == self.view)
{
[UIView animateWithDuration:0.6 animations:^
{
[self.signatureTextField setAlpha:0.2];
}];
}
}
@end