2015-10-21 8 views
13

पर धुंध प्रभाव के साथ सर्कल जोड़ें मैं मानचित्र पर ओवरले पर धुंध प्रभाव जोड़ने की कोशिश कर रहा हूं। मुझे वास्तव में नक्शे पर एक सर्कल पर धुंध प्रभाव की आवश्यकता है, जिस विधि को मैं प्राप्त करने के लिए उपयोग करता हूं वह महत्वपूर्ण नहीं है।एक MKMapView

मेरे पास एक कक्षा है जो MKCircleRenderer से फैली हुई है और मैं उस मानचित्र पर धुंधला प्रभाव जोड़ना चाहता हूं जिसमें यह शामिल है।

मैं -fillPath:inContext: विधि का उपयोग करने का प्रयास कर रहा था, लेकिन कोर ग्राफिक्स और कोर छवि पर मेरी अज्ञानता मुझे कहीं भी ले जाती है और मैं वास्तव में इस मुद्दे के बारे में वास्तव में खो गया हूं।

मेरा प्रयास CIFilter का उपयोग कर रहा था और इसके लिए मुझे CIImage की आवश्यकता थी जिसे मैंने संदर्भ से बनाने की कोशिश की थी। लेकिन मुझे CGBitmapContext, CGImage और न ही संदर्भ से किसी अन्य वर्ग को बनाने का कोई तरीका नहीं मिला। मैंने जिस भी विधि की कोशिश की, उसके परिणामस्वरूप न्यूल पर नतीजा क्यों हुआ। मैं जो भी कोशिश करता हूं उसे याद नहीं कर सकता, इसलिए मुझे इसके बारे में कुछ भी इंगित करने के बारे में खेद है।

- (instancetype)initWithOverlay:(id<MKOverlay>)overlay { 
    if (self = [super initWithOverlay:overlay]) { 
     self.strokeColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1]; 
     self.fillColor = [UIColor colorWithRed:0.4 green:0.2 blue:0.2 alpha:0.1]; 
     self.lineWidth = 1; 
    } 
    return self; 
} 

एक वैकल्पिक एक कस्टम MKAnnotation का उपयोग कर किया जा सकता है और UIVisualEffectView साथ दृश्य पर कलंक प्रभाव जोड़ें:

मेरी कक्षा वर्तमान में एक तरीकों कि वास्तव में ज्यादा कुछ नहीं है लागू करता है। ज़ूमिंग करते समय इस दृष्टिकोण के साथ कठिन हिस्सा आकार में वृद्धि/घट रहा है।

यह आईओएस 8

संपादित

पर काम करना चाहिए इस मामले में, सर्कल के अंदर पीछे नक्शा धुंधला किए जाने वाले

+0

क्या आप वास्तव में क्या हासिल करना चाहते हैं का एक स्क्रीनशॉट प्रदान कर सकते हैं? एक विशिष्ट सर्कल को छोड़कर मानचित्र को धुंधला करें? या केवल एक सर्कल धुंधला? यह ज़ूम-निर्भर क्यों है? – luk2302

+0

यदि आपको –

+0

की आवश्यकता है तो स्क्रीनशॉट दिखाएं तो यह बेहतर होगा। मैं एक धुंध सर्कल द्वारा कवर एक क्षेत्र चाहते हैं। क्षेत्र में एक चौथाई मील का त्रिज्या होना चाहिए, इसलिए यदि कोई ज़ूम इन/आउट करता है तो उसे अपना आकार बदलना चाहिए। मैं जल्द ही एक छवि जोड़ रहा हूँ। –

उत्तर

2

तो मैंने ओवरले के शीर्ष पर UIVisualEffectView का उपयोग करके समाप्त कर दिया। इस जगह को देखने के लिए चाल CADisplayLink का उपयोग करने में थी।

यहां कुछ कोड उदाहरण है जो नौकरी करता है (यह कुछ चीजों को अनदेखा करता है जिसे वास्तव में किसी ऐप पर ऐसा करने पर विचार किया जाना चाहिए, जैसे कि लिंक को हटाने, ट्रैक पर जो किया जाता है उसे ट्रैक करते हुए डीडएपियर को जोड़ा जाना चाहिए संभवतः सममित काम के साथ WillDissapear या कुछ, मैं viewDidLoad का उपयोग कर सकता हूं, मुझे लगता है, लेकिन परीक्षण करते समय इसे इस तरह से किया था)।

#import "ViewController.h" 
#import <MapKit/MapKit.h> 
#import <QuartzCore/QuartzCore.h> 

@interface ViewController() { 
    IBOutlet MKMapView *map; 
    UIView *ov; 
    MKCircle *c; 
    UIVisualEffectView *ev; 
} 

@end 

@implementation ViewController 

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 

    CLLocationCoordinate2D center = CLLocationCoordinate2DMake(40.7828647,-73.9675438); 
    c = [MKCircle circleWithCenterCoordinate:center radius:1000]; 
    [map addOverlay:c]; 
    MKCoordinateSpan span = MKCoordinateSpanMake(0.07, 0.07); 
    MKCoordinateRegion region = MKCoordinateRegionMake(center, span); 
    region = [map regionThatFits:region]; 
    [map setRegion:region animated:YES]; 

    ov = [[UIView alloc] init]; 
    ov.translatesAutoresizingMaskIntoConstraints = NO; 
    ov.backgroundColor = [UIColor clearColor]; 
    ov.clipsToBounds = YES; 
    ov.layer.borderWidth = 1; 
    ov.layer.borderColor = [UIColor blackColor].CGColor; 
    [map addSubview:ov]; 

    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; 
    ev = [[UIVisualEffectView alloc] initWithEffect:blur]; 
    [ov addSubview:ev]; 

    CADisplayLink *link = [CADisplayLink displayLinkWithTarget:self selector:@selector(update:)]; 
    [link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; 
} 

- (void)update:(CADisplayLink *)link { 
    ov.frame = [map convertRegion:MKCoordinateRegionForMapRect(c.boundingMapRect) toRectToView:map]; 
    ov.layer.cornerRadius = ov.frame.size.height/2; 
    ev.frame = CGRectMake(0, 0, ov.frame.size.width, ov.frame.size.height); 
} 

@end 

संपादित करें: स्क्रीनशॉट

2

यहां करने के लिए दो तरीके हैं उस।

एक आसान है, आप बस छवि का उपयोग कर सकते हैं।

आप उपयोगी निम्न छवियाँ मिल सकती है:

enter image description hereenter image description hereenter image description hereenter image description hereenter image description here

और उन्हें viewForAnnotation में उपयोग करने के लिए कोड:

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation 
{ 
    // ... get the annotation delegate and allocate the MKAnnotationView (annView) 
     if ([annotationDelegate.type localizedCaseInsensitiveCompare:@"NeedsBluePin"] == NSOrderedSame) 
     { 
      UIImage * image = [UIImage imageNamed:@"blue_pin.png"]; 
      UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease]; 
      [annView addSubview:imageView]; 
     } 
} 

अन्य विधि है कि प्रोग्राम के रूप में [मंडली खुद बनाना ]

यह कोड आपकी मदद कर सकता है।

import UIKit 
import AddressBook 
import AddressBookUI 
import MapKit 
import CoreLocation 
import MessageUI 
import Social 

class ViewController: UIViewController, ABPeoplePickerNavigationControllerDelegate, MFMailComposeViewControllerDelegate, MKMapViewDelegate { 

    @IBOutlet weak var name: UILabel! 
    @IBOutlet weak var email: UILabel! 
    @IBOutlet weak var photo: UIImageView! 
    @IBOutlet weak var map: MKMapView! 

    let locMan:CLLocationManager=CLLocationManager() 

    // Blurring Code 
    @IBOutlet weak var labelBackground: UIView! 
    var backgroundBlur: UIVisualEffectView! 


    @IBAction func newBFF(sender: AnyObject) { 
     let picker: ABPeoplePickerNavigationController = 
      ABPeoplePickerNavigationController() 
     picker.peoplePickerDelegate = self 
     presentViewController(picker, animated: true, completion: nil) 
    } 

    @IBAction func sendEmail(sender: AnyObject) { 
     var emailAddresses:[String]=[self.email.text!] 
     var mailComposer:MFMailComposeViewController = 
      MFMailComposeViewController() 
     mailComposer.mailComposeDelegate=self; 
     mailComposer.setToRecipients(emailAddresses) 

     presentViewController(mailComposer, animated: true, completion: nil) 
    } 

    func mailComposeController(controller: MFMailComposeViewController!, 
     didFinishWithResult result: MFMailComposeResult, error: NSError!) { 
     dismissViewControllerAnimated(true, completion: nil) 
    } 

    func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!) { 

     let friendName:String = ABRecordCopyValue(person, kABPersonFirstNameProperty).takeRetainedValue() as String as String 
     name.text=friendName 

     let friendAddressSet:ABMultiValueRef = ABRecordCopyValue(person, kABPersonAddressProperty).takeRetainedValue() 

     if ABMultiValueGetCount(friendAddressSet)>0 { 
      let friendFirstAddress: Dictionary = ABMultiValueCopyValueAtIndex(friendAddressSet, 0).takeRetainedValue() as NSDictionary 
      showAddress(friendFirstAddress) 
     } 

     let friendEmailAddresses:ABMultiValueRef = ABRecordCopyValue(person, kABPersonEmailProperty).takeRetainedValue() 

     if ABMultiValueGetCount(friendEmailAddresses)>0 { 
      let friendEmail: String = ABMultiValueCopyValueAtIndex(friendEmailAddresses, 0).takeRetainedValue() as String 
      email.text=friendEmail 
     } 

     if ABPersonHasImageData(person) { 
      photo.image = UIImage(data: ABPersonCopyImageData(person).takeRetainedValue()) 
     } 
    } 

    func showAddress(fullAddress:NSDictionary) { 
     let geocoder: CLGeocoder = CLGeocoder() 
     geocoder.geocodeAddressDictionary(fullAddress, completionHandler: 
      {(placemarks: [AnyObject]!, error: NSError!) -> Void in 
       let friendPlacemark:CLPlacemark = placemarks[0] as CLPlacemark 
       let mapRegion:MKCoordinateRegion = 
        MKCoordinateRegion(center: friendPlacemark.location.coordinate, 
         span: MKCoordinateSpanMake(0.2, 0.2)) 
       self.map.setRegion(mapRegion, animated: true) 
       let mapPlacemark: MKPlacemark = MKPlacemark(placemark: friendPlacemark) 
       self.map.addAnnotation(mapPlacemark) 
     }) 
    } 

    func mapView(aMapView: MKMapView!, 
     viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! { 
      let pinDrop:MKPinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myspot") 
      pinDrop.animatesDrop=true 
      pinDrop.canShowCallout=true 
      pinDrop.pinColor=MKPinAnnotationColor.Purple 
      return pinDrop 
    } 

    @IBAction func sendTweet(sender: AnyObject) { 
     let geocoder: CLGeocoder = CLGeocoder() 
     geocoder.reverseGeocodeLocation(map.userLocation.location, completionHandler: 
      {(placemarks: [AnyObject]!, error: NSError!) -> Void in 
       let myPlacemark:CLPlacemark = placemarks[0] as CLPlacemark 
       let tweetText:String = 
        "Hello all - I'm currently in \(myPlacemark.locality)!" 

       let tweetComposer: SLComposeViewController = 
        SLComposeViewController(forServiceType: SLServiceTypeTwitter) 

       if SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter) { 
        tweetComposer.setInitialText(tweetText) 
        self.presentViewController(tweetComposer, animated: true, completion: nil) 
       } 
     }) 
    } 


    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
     //let locMan:CLLocationManager=CLLocationManager() 
     locMan.requestWhenInUseAuthorization() 

     let blur: UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light) 
     backgroundBlur = UIVisualEffectView (effect: blur) 
     backgroundBlur.frame = labelBackground.frame 
     view.insertSubview(backgroundBlur, belowSubview: labelBackground) 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    override func preferredStatusBarStyle() -> UIStatusBarStyle { 
     return UIStatusBarStyle.LightContent 
    } 


} 
+1

शायद मैंने कुछ गलत व्यक्त किया, लेकिन संपादन पर सही ढंग से कहा गया है। मुझे सर्कल के पीछे नक्शा को धुंधला करने की ज़रूरत नहीं है, न कि नक्शे पर तैरने वाला एक सर्कल:/वैसे भी धन्यवाद। –

+1

एनोटेशन के लिए दृश्य ज़ूम AFAIK को अनदेखा कर देगा। यदि मैं दृश्य में ज़ूम इन या आउट करता हूं तो स्क्रीन पर एक ही आकार दिखाएगा, लेकिन मानचित्र पर दिखाए गए वास्तविक सामान के सापेक्ष नहीं। –