ios – 在MKMapView上添加具有模糊效果的圈子

ios – 在MKMapView上添加具有模糊效果的圈子,第1张

概述我试图在地图上的叠加层上添加模糊效果.我实际上需要在地图上的一个圆圈上的模糊效果,我使用的方法不是那么重要. 我有一个类从MKCircleRenderer扩展,我想在它覆盖的地图上添加一个模糊效果. 我正在尝试使用-fillPath:inContext:方法,但是我对Core Graphics和Core Image的无知导致我无处不在,我真的很失落了这个问题. 我试图使用CIFilter,因此我需 我试图在地图上的叠加层上添加模糊效果.我实际上需要在地图上的一个圆圈上的模糊效果,我使用的方法不是那么重要.

我有一个类从MKCircleRenderer扩展,我想在它覆盖的地图上添加一个模糊效果.

我正在尝试使用-fillPath:inContext:方法,但是我对Core Graphics和Core Image的无知导致我无处不在,我真的很失落了这个问题.

我试图使用CIFilter,因此我需要一个CIImage,我试图从上下文创建.但是我发现没有办法从上下文创建一个CGBitmapContext,CGImage和任何其他类.我尝试的任何方法导致了NulL,没有进一步的细节为什么.我不记得我试过的所有,所以我很抱歉没有指出任何事情.

我的课程目前实现一个不太重要的方法:

- (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在视图中添加模糊效果.这种方法的难点在于缩放时会增大/减小大小.

这应该适用于iOS 8

编辑

在这种情况下,圆圈内侧的地图应该模糊

解决方法 有两种方法可以做到这一点.

一个很简单,你可以使用图像

您可能会发现以下图像很有用:

并在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 UIKitimport AddressBookimport AddressBookUIimport MapKitimport CoreLocationimport MessageUIimport Socialclass 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,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,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,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    }}
总结

以上是内存溢出为你收集整理的ios – 在MKMapView上添加具有模糊效果的圈子全部内容,希望文章能够帮你解决ios – 在MKMapView上添加具有模糊效果的圈子所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1112411.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存