0
대나무 책과 종이 같은 앱을 사용하고 있습니다. iPad에서는 경험이 정말 좋은데, 어떻게 작동합니까? 어떤 기술이 선이나 곡선을 화면에 그릴 때 사용됩니까?iOS 플랫폼에서 선을 그리는 방법
대나무 책과 종이 같은 앱을 사용하고 있습니다. iPad에서는 경험이 정말 좋은데, 어떻게 작동합니까? 어떤 기술이 선이나 곡선을 화면에 그릴 때 사용됩니까?iOS 플랫폼에서 선을 그리는 방법
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = NO;
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2) {
//self.imageView.image = nil;
return;
}
lastPoint = [touch locationInView:self.view];
lastPoint.y -= 20;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
currentPoint.y -= 20;
CGFloat components[3];
[self getRGBComponents:components forColor:self.colorView.backgroundColor];
NSLog(@"%f %f %f", components[0], components[1], components[2]);
UIGraphicsBeginImageContext(self.view.frame.size);
[self.imageView.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), components[0], components[1], components[2],5.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeNormal);
CGContextStrokePath(UIGraphicsGetCurrentContext());
self.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
mouseMoved++;
if (mouseMoved == 10) {
mouseMoved = 0;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2) {
//self.imageView.image = nil;
return;
}
if(!mouseSwiped) {
CGFloat components[3];
[self getRGBComponents:components forColor:self.colorView.backgroundColor];
NSLog(@"%f %f %f", components[0], components[1], components[2]);
UIGraphicsBeginImageContext(self.view.frame.size);
[self.imageView.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), components[0], components[1], components[2], 5.0);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
self.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
}
또한 링크를 확인 정확하게 프로그래밍 질문,하지만 아이폰 OS에서이 높습니다 아니에요
http://www.techotopia.com/index.php/An_iOS_4_iPhone_Graphics_Drawing_Tutorial_using_Quartz_2D
https://stackoverflow.com/questions/6449661/drawing-2d-images-on-iphone-tutorials
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_freehand-drawing/
http://www.raywenderlich.com/18840/how-to-make-a-simple-drawing-app-with-uikit
Quartz Framework를 사용하여 선과 모양을 그리는 것입니다. – ATaylor
가능한 중복 http://stackoverflow.com/questions/3128752/draw-line-in-uiview –