2012-05-22 18 views
5

मैं ओवरले व्यू में दो बिंदुओं के बीच सीधी रेखा खींचने की कोशिश कर रहा हूं। एमकेओवरलेव्यू विधि में, मुझे लगता है कि मैं सही तरीके से कर रहा हूं लेकिन मुझे समझ में नहीं आता कि यह किसी भी रेखा को क्यों नहीं खींच रहा है ...लाइन ओवरले व्यू पर खींचे नहीं जा रहे हैं

क्या किसी को पता है क्यों?

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale 
      inContext:(CGContextRef)context 
{ 
    UIGraphicsPushContext(context); 

    MKMapRect theMapRect = [[self overlay] boundingMapRect]; 
    CGRect theRect = [self rectForMapRect:theMapRect]; 

    // Clip the context to the bounding rectangle. 
    CGContextAddRect(context, theRect); 
    CGContextClip(context); 

    CGPoint startP = {theMapRect.origin.x, theMapRect.origin.y}; 
    CGPoint endP = {theMapRect.origin.x + theMapRect.size.width, 
     theMapRect.origin.y + theMapRect.size.height}; 

    CGContextSetLineWidth(context, 3.0); 
    CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 

    CGContextBeginPath(context); 
    CGContextMoveToPoint(context, startP.x, startP.y); 
    CGContextAddLineToPoint(context, endP.x, endP.y); 
    CGContextStrokePath(context); 

    UIGraphicsPopContext(); 
} 

आपकी मदद के लिए धन्यवाद।

उत्तर

3

लाइन startP और endP जो CGPoint मान हैं का उपयोग कर तैयार की जा रही है, लेकिन वे theMapRect जो MKMapPoint मान का उपयोग कर प्रारंभ कर रहे हैं।

इसके बजाय, उन्हें theRect का उपयोग करके प्रारंभ करें, जिसे आप से rectForMapRect का उपयोग कर परिवर्तित कर रहे हैं।

इसके अलावा, लाइन चौड़ाई के लिए, आप इसे MKRoadWidthAtZoomScale फ़ंक्शन का उपयोग करके स्केल करना चाह सकते हैं। अन्यथा, 3.0 की एक निश्चित रेखा चौड़ाई तब तक दिखाई नहीं देगी जब तक आप बहुत करीब में ज़ूम नहीं कर लेते। एक कस्टम MKOverlayView के बजाय

CGPoint startP = {theRect.origin.x, theRect.origin.y}; 
CGPoint endP = {theRect.origin.x + theRect.size.width, 
    theRect.origin.y + theRect.size.height}; 

CGContextSetLineWidth(context, 3.0 * MKRoadWidthAtZoomScale(zoomScale)); 


अंत में, क्यों एक MKPolylineView का उपयोग नहीं लाइनों मैन्युअल ड्राइंग से बचने के लिए:

बदली हुई कोड इस प्रकार दिखाई देगा?

+0

यह काम किया !! आपका बहुत बहुत धन्यवाद!!! –

+0

हाय, मेरे पास एक और सवाल है ... यदि मैं CGPoint को सीमाबद्ध करने से CGPoint प्रारंभ करना चाहता हूं, तो मुझे कैसे करना चाहिए ???? –

+0

ओह .. और कारण मैं MkPolylineView का उपयोग नहीं कर रहा हूं, मुझे केवल तीर नहीं बल्कि तीर खींचने की आवश्यकता है .... –

संबंधित मुद्दे