UILabel
에서 다른 행으로 드래그하는 프로그램을 작성 중입니다. DragView라는 UIView
하위 클래스를 만들고 drawRect
메서드를 오버라이드했습니다. UIView
을 RootController
보기의 하위보기로 만들었습니다. DragView
이 명확하게 표시되고 drawRect
메서드가 확실히 호출되고 있지만 선이 표시되지 않습니다.UIPanGestureRecognizer를 사용하여 ios에서 행을 드래그하는 방법
이들은 (내가 생각하기에) 관련 코드 조각입니다.
//DragView.m
- (void)drawRect:(CGRect)rect
{
if (context == nil)
{
context = UIGraphicsGetCurrentContext();
}
if (_drawLineFlag)
{
CGContextSetLineWidth(context,2.0);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGFloat components[] = {0.0,0.0,1.0,1.0};
CGColorRef color = CGColorCreate(colorspace, components);
CGContextSetStrokeColorWithColor(context,color);
CGContextMoveToPoint(context,_startX, _startY);
CGContextAddLineToPoint(context,_currentX,_currentY);
CGContextStrokePath(context);
}
}
DrawProgramAppDelegate
- (void) initializeUI
{
.....
dragView = [[DragView alloc] initWithFrame:CGRectMake(0.0f,0.0f,1024.0f,768.0f)] ;
[view addSubview: dragView];
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[dragView addGestureRecognizer:panGestureRecognizer];
.....
}
이벤트 핸들러는 다음과 같습니다 도와
- (void) handlePan:(UIPanGestureRecognizer *) recognizer
{
CGPoint point = [recognizer translationInView:dragView];
[dragView setCurrentX:point.x];
[dragView setCurrentY:point.y];
[dragView setDrawLineFlag:YES];
[view bringSubviewToFront:drawView];
[dragView drawRect:CGRectMake (0.0f,0.0f,768.0f, 1024.0f)];
}
많은 감사합니다.
존이
어떻게 검색하고 찾을 수 있습니까? 나는 drwan 선을 두 드렸을 때 hightlight하고 싶다. 이 코드베이스 (http://stackoverflow.com/questions/25811490/draw-line-using-uipinchgeurerecognizer). – Sierra