실제로 전에 이런 짓을했는지, 그래서 당신에게 정확한 코드를 제공 할 수 있습니다 : D
를이 단지 그림 부분, 당신은 self.userInteractionEnabled를 제거 달리, 별도의 클래스의 터치 이벤트를 (구현입니다 = NO,하는 .m 파일에 BOOL 드래그
라인이 그려 져야 경우 LineView을 알려줍니다
#import <UIKit/UIKit.h>
@interface LineView : UIView
{
CGPoint start;
CGPoint end;
BOOL dragged;
}
@property CGPoint start, end;
@property BOOL dragged;
@end
LineView.h합니다.
LineView.m
#import "LineView.h"
@implementation LineView
@synthesize start, end, dragged;
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame: frame])
{
self.userInteractionEnabled = NO;
self.backgroundColor = [UIColor clearColor];
}
return self;
}
#pragma mark Setters
-(void) setStart: (CGPoint) s
{
start = s;
[self setNeedsDisplay];
}
-(void) setEnd: (CGPoint) e
{
end = e;
[self setNeedsDisplay];
}
#define LINE_COLOR [UIColor redColor]
#define CIRCLE_COLOR [UIColor redColor]
#define LINE_WIDTH 5
#define CIRCLE_RADIUS 10
- (void)drawRect:(CGRect)rect
{
CGContextRef c = UIGraphicsGetCurrentContext();
if(dragged) {
[LINE_COLOR setStroke];
CGContextMoveToPoint(c, start.x, start.y);
CGContextAddLineToPoint(c, end.x, end.y);
CGContextSetLineWidth(c, LINE_WIDTH);
CGContextClosePath(c);
CGContextStrokePath(c);
[CIRCLE_COLOR setFill];
CGContextAddArc(c, start.x, start.y, CIRCLE_RADIUS, 0, M_PI*2, YES);
CGContextClosePath(c);
CGContextFillPath(c);
CGContextAddArc(c, end.x, end.y, CIRCLE_RADIUS, 0, M_PI*2, YES);
CGContextClosePath(c);
CGContextFillPath(c);
}
}
- (void)dealloc
{
[super dealloc];
}
@end
그리고 난 당신이 뷰가 다른 뷰 이상이어야한다는 것을 알고 있기를 바랍니다. 줄을 드래그 한 위치를 감지하려면 터치 이벤트를 처리하는 클래스에서 touchesEnded :를 사용하십시오. – tadejsv
wow thats great, 나는 시도해보고 알려 드리겠습니다. – Brodie
괜찮습니다. 내가 필요로하는 것보다 훨씬 적게 알고있다. 사용자가 tableViewCell의 단추에서 손가락을 끈 상태에서 구현합니까? – Brodie