【发布时间】:2015-04-24 10:10:57
【问题描述】:
我正在尝试制作一个应用程序,让用户在特定区域签名,然后保存图像以将其发送到电子邮件中。但是我在将图像传递给我的主视图控制器时遇到了一些困难。这是我的代码:
#import "LinearInterpView.h"
@implementation LinearInterpView
{
UIBezierPath *path; // (3)
}
- (id)initWithCoder:(NSCoder *)aDecoder // (1)
{
if (self = [super initWithCoder:aDecoder])
{
[self setMultipleTouchEnabled:NO]; // (2)
[self setBackgroundColor:[UIColor whiteColor]];
path = [UIBezierPath bezierPath];
[path setLineWidth:2.0];
}
return self;
}
- (void)drawRect:(CGRect)rect // (5)
{
[[UIColor blackColor] setStroke];
[path stroke];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
[path moveToPoint:p];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
[path addLineToPoint:p]; // (4)
[self setNeedsDisplay];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesMoved:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesEnded:touches withEvent:event];
}
+ (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
@end
当我使用 Prepareforsegue 方法时,它不起作用,因为视图控制器没有再次加载。我想让用户签署该区域,然后在包含子视图的同一个视图控制器上按下一个按钮,并使用代码创建一封电子邮件:
[mailComposer addAttachmentData:imageData mimeType:@"image/png" fileName:@"Signature”];
如何在不先按下按钮或其他东西的情况下传递数据。非常感谢所有帮助!
【问题讨论】:
-
如果是
UIView,可以设置自定义委托通知UIViewController签名已经完成。 -
而且,我如何设置自定义委托,您的意思是,用几行扩展代码“touchended”,然后使用 Prepareforsegue 方法发送图像?还是我混淆了这一切? @Larme
标签: objective-c uiview message-passing