내 앱에서 UIBezierPath로 그릴 수있었습니다. 이제 버튼을 누르고있는 사용자가 다른 색상을 선택할 수 있도록 UIColor 변수를 추가했습니다. 사용자가 색상을 변경하고 새 색상으로 그리기를 시작하면 이미 그려진 모든 패스에 새 색상이 적용됩니다.UIBezierPath 다른 색상
개체가 이미 그려진 경로의 색을 변경하지 않도록하려면 어떻게해야합니까?
여기 내 코드입니다. 코드의 모든 예제가 많이 감사드립니다! :)
(내 UIColor 변수가 AppDelegate에에 storaged하고 난 다른 viewControlle에서 새로 고침 메소드를 호출하고 있습니다.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.backgroundColor = [UIColor whiteColor];
myPath = [[UIBezierPath alloc] init];
myPath.lineCapStyle = kCGLineCapRound;
myPath.miterLimit = 0;
myPath.lineWidth = 5;
brushPattern = app.currentColor;
}
return self;
}
-(void)refresh {
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
brushPattern = app.currentColor;
}
- (void)drawRect:(CGRect)rect {
[brushPattern setStroke];
for (UIBezierPath *_path in pathArray)
[_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
myPath = [[UIBezierPath alloc] init];
myPath.lineWidth = 5;
UITouch *mytouch = [[touches allObjects] objectAtIndex:0];
[myPath moveToPoint:[mytouch locationInView:self]];
[pathArray addObject:myPath];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *mytouch = [[touches allObjects] objectAtIndex:0];
[myPath addLineToPoint:[mytouch locationInView:self]];
[self setNeedsDisplay];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}
이미 다음 대답에 게시 한 경우는? 모든 솔루션을 가지고, 그래서 도움이 될 것입니다 수행 다른 사람들에게. –
아니, 죄송합니다. 나는 시스템을 바꿀 필요가 있었다. ... – BalestraPatrick