语境陌生性
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

I have a little code module that should refer as signature panel so that the user can sign on this panel with his finger. The whole thing runs on the iPad. Now, I managed to do the usual touchesBegan(), touchesMoved(), touchesEnded() carousel to make him sign on that panel. While signing, I draw his signature on the main view. However, due to whatever reason, the image appears twice: once correctly and once upside down above the main signature (see image). Since I don't see any translating being done in my code, I suspect that the whole code might be incorrect, but I don't know why. Does anyone know what I'm doing wrong here?

enter image description here

#import "RMSignatureView.h"
#import <QuartzCore/QuartzCore.h>

@interface RMSignatureView() {
  CGPoint origin;
}
-(void) setupLayer;
@property (nonatomic, retain) UIImage* image;
@end

@implementation RMSignatureView

@synthesize image;

-(void) dealloc {
  [image release];
  [super dealloc];
}

- (id)initWithFrame:(CGRect)frame {
  self = [super initWithFrame:frame];
  if (self) {
    [self setupLayer];
  }
  return self;
}

-(id) initWithCoder:(NSCoder *)aDecoder {
  if ([super initWithCoder:aDecoder] == self) {
    [self setupLayer];
  }
  return self;
}

-(void) setupLayer {
  self.layer.cornerRadius = 10;
  self.layer.borderColor = [UIColor colorWithRed:109.0/256.0 green:149.0/256.0 blue:224.0/256.0 alpha:1.0].CGColor;
  self.layer.borderWidth = 0.5f;
}

- (void)drawRect:(CGRect)rect {
  CGContextRef context = UIGraphicsGetCurrentContext();
  CGContextSaveGState(context);
  CGContextSetStrokeColorWithColor(context, [UIColor grayColor].CGColor);
  CGFloat sizes[2];
  sizes[0] = 1;
  sizes[1] = 1;
  CGContextSetLineDash(context, 0, sizes, 2);
  CGContextMoveToPoint(context, rect.origin.x + 50, rect.origin.y + rect.size.height - 30);
  CGContextAddLineToPoint(context, rect.origin.x + rect.size.width - 50, rect.origin.y + rect.size.height - 30);
  CGContextStrokePath(context);
  CGContextSetLineDash(context, 0, NULL, 0);

  if (image)
    CGContextDrawImage(context, rect, image.CGImage);

  CGContextRestoreGState(context);
}

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  UITouch* touch = [touches anyObject];
  origin = [touch locationInView:self];
}

-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
  origin.x = -1;
  origin.y = -1;
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  origin.x = -1;
  origin.y = -1;
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  UITouch* touch = [touches anyObject];
  if (origin.x != -1 && origin.y != -1) {
    UIGraphicsBeginImageContext(self.frame.size);
    @try {
      CGContextRef context = UIGraphicsGetCurrentContext();
      CGContextSaveGState(context);      
      if (image)
        CGContextDrawImage(context, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), image.CGImage);

      CGContextMoveToPoint(context, origin.x, origin.y);
      origin = [touch locationInView:self];
      CGContextAddLineToPoint(context, origin.x, origin.y);
      CGContextStrokePath(context);
      self.image = UIGraphicsGetImageFromCurrentImageContext();  
      CGContextRestoreGState(context);
    }
    @finally {
      UIGraphicsEndImageContext();
    }
  }
  [self setNeedsDisplay];
}

@end

#0

Found it.. Quartz has (0, 0) in the lower left instead of upper left.

推荐文章

如何在不修改ulimit的情况下处理nodejs EMFILE异常?

如何在不修改ulimit的情况下处理nodejs EMFILE异常?

推荐文章

在PHP中调用chroot

在PHP中调用chroot

推荐文章

如何将目录中的内容添加到C中的列表框中#

如何将目录中的内容添加到C中的列表框中#

推荐文章

地理空间索引的划分查询

地理空间索引的划分查询

推荐文章

为某个词的首字母等设计样式

为某个词的首字母等设计样式

推荐文章

从表中删除后自动递增

从表中删除后自动递增

推荐文章

Pygame.transform.rotate错误

Pygame.transform.rotate错误

推荐文章

Zend_lucene口音搜索

Zend_lucene口音搜索

推荐文章

使用子进程在Python中执行命令行?

使用子进程在Python中执行命令行?

推荐文章

Firefox扩展/加载项二进制组件向后兼容性

Firefox扩展/加载项二进制组件向后兼容性

推荐文章

确保只有一个应用程序实例

确保只有一个应用程序实例

推荐文章

如何使用RDoc的`:include:`指令?

如何使用RDoc的`:include:`指令?

推荐文章

如何在列表理解中设置严格性?

如何在列表理解中设置严格性?

推荐文章

Javascript匹配regex-防止贪婪

Javascript匹配regex-防止贪婪

推荐文章

Node.js:解析JSON对象

Node.js:解析JSON对象

推荐文章

从底部调整NSWindow高度?

从底部调整NSWindow高度?