Signature.h ファイル
#import <UIKit/UIKit.h>
@interface Signature : UIViewController
{
CGPoint firstTouch;
CGPoint lastTouch;
UIColor *pointColor;
CGRect *points;
int npoints;
CGPoint location;
// UIImageView *signatureImageView;
}
@property CGPoint firstTouch;
@property CGPoint lastTouch;
@property (nonatomic, retain) UIColor *pointColor;
@property CGRect *points;
@property int npoints;
@property (retain, nonatomic) IBOutletCollection(UIImageView) NSArray *drawSign;
@property CGPoint location;
@property (retain, nonatomic) IBOutletCollection(UIImageView) NSArray *signatureImageView;
- (IBAction)savePressed:(id)sender;
- (IBAction)clearPressed:(id)sender;
@end
Signature.m
#import "Signature.h"
@interface Signature ()
@end
@implementation Signature
@synthesize drawSign;
@synthesize signatureImageView;
@synthesize firstTouch;
@synthesize lastTouch;
@synthesize pointColor;
@synthesize points;
- (id)initWithFrame:(CGRect)frame
{
return self;
}
- (id)initWithCoder:(NSCoder *)coder
{
if(self = [super initWithCoder:coder])
{
self.npoints = 0;
}
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
NSLog(@"initwithnibname");
return self;
}
- (void)viewDidLoad
{
NSLog(@"viewdidload");
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
NSLog(@"view did unload");
[self setSignatureImageView:nil];
[self setDrawSign:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touch has began");
UITouch *touch = [touches anyObject];
self.location = [touch locationInView:self.view];
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touches moves");
UITouch *touch = [touches anyObject];
CGPoint currentLocation = [touch locationInView:self.view];
UIGraphicsBeginImageContext(self.view.frame.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
//[self.drawSign.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineWidth(ctx, 5.0);
CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, location.x, location.y);
NSLog(@"%f x is",location.x);
NSLog(@"%f y is",location.y);
CGContextAddLineToPoint(ctx, currentLocation.x, currentLocation.y);
CGContextStrokePath(ctx);
// self.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
location = currentLocation;
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touches ended");
UITouch *touch = [touches anyObject];
CGPoint currentLocation = [touch locationInView:self.view];
UIGraphicsBeginImageContext(self.view.frame.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
//[self.view.image drawInRect:CGRectMake(0, 0, self.frame.view.size.width, self.frame.view.size.height)];
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineWidth(ctx, 5.0);
CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, location.x, location.y);
CGContextAddLineToPoint(ctx, currentLocation.x, currentLocation.y);
CGContextStrokePath(ctx);
// self.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
location = currentLocation;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)dealloc {
[signatureImageView release];
[super dealloc];
}
- (IBAction)savePressed:(id)sender {
NSLog(@"save pressed");
}
- (IBAction)clearPressed:(id)sender {
NSLog(@"cancel pressed");
}
@end
私のプロジェクトに関連する 2 つのファイルを見つけてください。一つの見方から、私はこの見方に来ています。ここで、ユーザーが描画したものをすべて保存する必要があります。座標を取得できますが、描画できません。私はいくつかの試みを試みましたが、どちらも機能していないようです.Signature.mファイル自体でコメント化された方法でそれらを見つけてください. 間違いを指摘して訂正してください。