目前,我遇到了一个有点危险的问题。我正在做的是在核心图形的帮助下擦除图像并在同一图像上应用旋转效果。当我只是擦除图像时,擦除工作正常,但是当我先旋转该图像然后擦除同一图像时。当我移动以擦除图像的任何特定像素时,图像变得模糊并且图像的高度正在减小。这是我用来擦除图像的代码片段:-
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
mPreviousPoints = [touch locationInView:self];
mPreviousPoints.y = mPreviousPoints.y ;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint currentPoint = [touch locationInView:self];
currentPoint.y = currentPoint.y ;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
[self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetBlendMode(currentContext,kCGBlendModeClear);
CGContextSetLineCap(currentContext, kCGLineCapRound);
CGContextSetLineWidth(currentContext, 20);
CGContextSetStrokeColorWithColor(currentContext, [[UIColor clearColor] CGColor]);
CGContextBeginPath(currentContext);
CGContextMoveToPoint(currentContext, mPreviousPoints.x , mPreviousPoints.y );
CGContextAddLineToPoint(currentContext, currentPoint.x , currentPoint.y);
CGContextStrokePath(currentContext) ;
self.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
如果我不旋转图像,代码工作正常。
我也尝试使用触摸事件旋转图像,但没有任何变化,所以这是我在我的应用程序中使用的滚动代码:-
#pragma mark Rotation Gesture
- (void)rotateImage:(UIRotationGestureRecognizer *)recognizer
{
if (objAppDelegate.touchBool == YES)
{
if([recognizer state] == UIGestureRecognizerStateEnded)
{
previousRotation = 0.0;
return;
}
CGFloat newRotation = 0.0 - (previousRotation - [recognizer rotation]);
CGAffineTransform currentTransformation = touchImageView.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransformation, newRotation);
touchImageView.transform = newTransform;
previousRotation = [recognizer rotation];
}
}
我正在发布屏幕截图,以便您可以正确理解我的问题。所以,请看看它并帮助我。
如果可以,请你帮助我!
提前致谢 :)