旋转时触摸画

时间:2012-02-13 16:16:49

标签: xcode ipad

我正在制作一个触摸绘制应用程序,一切都工作正常,但是当我旋转我的iPad时,我触摸的线条在我手指上方5厘米处。

iv一直在谷歌搜索,试图找出x& y旋转时会发生变化。

你能帮助我吗?

我的代码用于绘制它:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

mouseSwiped = YES;

UITouch *touch = [touches anyObject];   
CGPoint currentPoint = [touch locationInView:self.view];
currentPoint.y -= -20;


UIGraphicsBeginImageContext(self.view.frame.size);

[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSaveGState(UIGraphicsGetCurrentContext());
CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), f5);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), f1, f2, f3, f4);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
CGContextRestoreGState(UIGraphicsGetCurrentContext());
UIGraphicsEndImageContext();

lastPoint = currentPoint;


mouseMoved++;

if (mouseMoved == 10) {
    mouseMoved = 0;}}

1 个答案:

答案 0 :(得分:1)

我在我的appDelegate中使用了边界并在我的绘图代码中使用了框架... 我改为:

 UIGraphicsBeginImageContext(self.view.bounds.size);

[drawImage.image drawInRect:CGRectMake(0, 0, self.view.bounds.size.width,self.view.bounds.size.height)];