2017-12-04 3 views
1

여기에 그다지 말할 것도 없습니다. 그냥, 내 UIView 추가됩니다 STROKE 없습니다. drawRect로 내 자신의 UIView에 그리기

#import "DrawingLayerView.h" 

@implementation DrawingLayerView 

UIBezierPath *newPath; 

- (void)startTouch:(CGPoint)point; 
{ 
    [newPath moveToPoint:point]; 
} 

- (void)drawRect:(CGRect)rect { 
    [[UIColor redColor] setStroke]; 
    [newPath stroke]; 
} 

- (void)drawShape:(CGPoint)point 
{ 
    [newPath addLineToPoint: point]; // (4) 
    [self setNeedsDisplay]; 
} 

- (void)endTouch:(CGPoint)point { 
    [newPath removeAllPoints]; 
} 

@end 

DrawingLayerView.h

UIView에 대한 사용자 정의 클래스입니다.

drawRect 함수는 확실히 호출되었지만 획이 작성되지 않았습니다.

자세한 정보가 필요하면 알려주십시오. 나에게 말해줘. 나는 그것을 얻을 것이다!

+0

danh가 말한 것처럼'newPath'를 전역으로 선언했습니다. 그것이 ivar이 되길 원한다면, 선언 앞에'{'를 넣고 선언 뒤에'}'를 넣으십시오. 아니면 개인 클래스 확장으로 이동하십시오. 또는 더 좋게 만들면 속성이됩니다 (이 속성을 .m 파일의 개인 클래스 확장에 배치하면 개인 속성이됩니다). – Rob

답변

1

적어도 한 가지의 인스턴스를 표시하지 않는 것은 newPath의 초기화이다. 시작시 touch : self.newPath = [UIBezierPath bezierPath]; (self.newPath를 사용하는 속성으로 지정하십시오. 그렇지 않으면 암시 적으로 정적으로 선언됩니다).

0

drawShape으로 전화하는 방법/장소를 보여줄 수 있습니다. 그것을 부를만한 것은 없습니다. 또한, 당신이 그 일을하는 가정, 당신이 이제까지 작업을 코드에 필요한 UIBezierPath, 예컨대 :

- (void)startTouch:(CGPoint)point   // note, no semicolon 
{ 
    newPath = [UIBezierPath bezierPath]; // note, create a `UIBezierPath` before you try to `moveToPoint`, or later, `addLineToPoint` 
    [newPath moveToPoint:point]; 
}