5
투명 영역을 브러시로 그립니다.하지만 코드가 잘 작동하지 않습니다. 누군가 나를 도와 줄 수 있다고 생각합니다. 내 코드 :내 손가락이 움직일 때 이미지의 투명한 영역을 어떻게 채울 수 있습니까?
// Handles the start of a touch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self bounds];
UITouch *touch = [[event touchesForView:self] anyObject];
if (![image isPointTransparent:[touch locationInView:self]]
|| ![image isPointTransparent:[touch previousLocationInView:self]])
{
return;
}
firstTouch = YES;
// Convert touch point from UIView referential to OpenGL one (upside-down flip)
location = [touch locationInView:self];
location.y = bounds.size.height - location.y;
}
// Handles the continuation of a touch.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self bounds];
UITouch *touch = [[event touchesForView:self] anyObject];
if (![image isPointTransparent:[touch locationInView:self]]
|| ![image isPointTransparent:[touch previousLocationInView:self]])
{
return;
}
// Convert touch point from UIView referential to OpenGL one (upside-down flip)
if (firstTouch)
{
firstTouch = NO;
previousLocation = [touch previousLocationInView:self];
previousLocation.y = bounds.size.height - previousLocation.y;
}
else
{
location = [touch locationInView:self];
location.y = bounds.size.height - location.y;
previousLocation = [touch previousLocationInView:self];
previousLocation.y = bounds.size.height - previousLocation.y;
}
// Render the stroke
[self renderLineFromPoint:previousLocation toPoint:location];
}
// Handles the end of a touch event when the touch is a tap.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self bounds];
UITouch *touch = [[event touchesForView:self] anyObject];
if (![image isPointTransparent:[touch locationInView:self]] || ![image isPointTransparent:[touch previousLocationInView:self]])
{
return;
}
if (firstTouch)
{
firstTouch = NO;
previousLocation = [touch previousLocationInView:self];
previousLocation.y = bounds.size.height - previousLocation.y;
[self renderLineFromPoint:previousLocation toPoint:location];
}
}
귀하의 문제는 무엇입니까? 코드를보고 추측 할 수 없으므로 발생한 문제에 대해 자세히 설명하십시오. 응용 프로그램을 실행할 때 잘못된 점을 알려주십시오. – klcjr89
"손가락으로 페인트하는 법"을 보여주는 WWDC 2012 비디오가 아주 훌륭합니다. – matt
나는 그림 응용 프로그램 만들기, 알파 영역이있는 이미지에 대한 생각 그리고이 영역이 아마도 불규칙한 것 같이 Objective-c를 배우기 시작했습니다. 나는 이미지 위에서 손가락을 움직일 때 알파 영역에 그려지는 지점을 원한다. – bencore