Tôi muốn vẽ vùng trong suốt bằng cọ, nhưng mã của tôi không hoạt động tốt. Tôi nghĩ ai đó có thể giúp tôi ở đây. Mã của tôi:Tôi có thể điền vào vùng trong suốt của hình ảnh như thế nào khi ngón tay của tôi di chuyển trên
// 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];
}
}
Chính xác thì vấn đề của bạn là gì? Vui lòng giải thích vấn đề bạn gặp phải là gì, vì chúng tôi không thể đoán được bằng cách xem mã của bạn. Hãy cho chúng tôi biết điều gì xảy ra khi bạn chạy ứng dụng của mình. – klcjr89
Có một video WWDC 2012 rất hay hiển thị cách "vẽ bằng ngón tay của bạn". – matt
Tôi bắt đầu tìm hiểu Objective-c với ứng dụng vẽ , Suy nghĩ về một hình ảnh với khu vực alpha, và khu vực này có thể bất thường. Tôi chỉ muốn vẽ điểm trên khu vực alpha khi tôi di chuyển ngón tay của mình lên hình ảnh. – bencore