Drawing an image is completely out
Hi I'm using this code below to let a user "draw" their signature on a UIView component on my app:
UIGraphicsBeginImageContext(signature.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, signature.frame.size.width, signature.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext()
The issue I am having is that the drawing is not only is the drawing not in line with the pointer when in use in the simulator, the image is going outside of the designated UIView compontent and is getting smaller/out of focus the more I draw, as you can see in this image: alt text http://dl.dropbox.com/u/1545603/iphone-signature-issues.png
And after开发者_如何学Python a few lines, showing the boundaries of the exact are of where I can draw: alt text http://dl.dropbox.com/u/1545603/iphone-signature-issues2.png
Any ideas on what's happening here?
lastPoint.y
is defined as: lastPoint.y -= 20;
Any ideas on what on earth is happening here?
Perhaps, instead of using your screen for the location and drawing to the white view, you have it the other way around therefore causing the line to go outside the white view.
Just an idea. Sorry, but from my iPhone that is the best answer I can give.
By the way I really recommend on device debugging. I find loads of usability flaws and it it is much better for gaugeing the performance.
I can't wait to see this app, email me the details when you can and I'll have a look on Friday. If you would like to, I have a computing project app and a website for you to beta/alpha test for me!
Dan
Ok, figured it out:
I might post up the code later, but, the UIView to draw on was set to:
signature.frame
whereas it should be signature.bounds
for all properties.
Finally, remove all lastPoint.y
and currentPoint.y
definitions.
Now, at this point, I will consider using variables to replace UIGraphicsGetCurrentContext()
精彩评论