Reputation: 445
In Swift i will try to set pin location(zPosition) on Top ,I am adding 10 pin on Map ,Current pin(Any one pin) showing on top and these current pin image is change, But its not showing on top , Please help me Here is my Code I have Try These code
// pinView!.layer.zPosition = 1
//pinView?.bringSubviewToFront(self.view)
pinView!.superview!.bringSubviewToFront(view)
App Crash on These Line
pinView!.superview!.bringSubviewToFront(view)
and Its return me fatal error: unexpectedly found nil while unwrapping an Optional value Please Help me How to pin show on Top
Here is my Code
func mapView(mapView: MKMapView,
viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?{
if annotation is MyAnnotation == false{
return nil
}
/* First typecast the annotation for which the Map View has
fired this delegate message */
let senderAnnotation = annotation as! MyAnnotation
// -------------------------- For ios 9 -------------------
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if pinView == nil {
pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.canShowCallout = true
}else{
pinView!.annotation = annotation
}
pinView!.tag = senderAnnotation.getTag;
// print(senderAnnotation.getTag)
if annotation is MyAnnotation {
print(senderAnnotation.pinColor)
if(senderAnnotation.pinColor == .Red)
{
if(currentIndex == senderAnnotation.getTag)
{
print("currentIndex==\(currentIndex)********")
pinView!.image = UIImage(named: "jivemap_pin_rough_o.png")
// pinView!.layer.zPosition = 1
//pinView?.bringSubviewToFront(self.view)
pinView!.superview!.bringSubviewToFront(view)
}else
{
pinView!.image = UIImage(named: "jivemap_pin_rough_g.png")
}
}
else
{
if(currentIndex == senderAnnotation.getTag)
{
print("currentIndex==*********\(currentIndex)********")
pinView!.image = UIImage(named: "jivemap_pin_o.png")
// pinView!.layer.zPosition = 1
//pinView?.bringSubviewToFront(self.view)
pinView!.superview!.bringSubviewToFront(view)
}else
{
pinView!.image = UIImage(named: "jivemap_pin_g.png")
}
}
pinView!.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure) as UIView
// pinView
// return pinView
}
return pinView
//return annotationView
}
I have one more problem , Can we select the zoom to show all the 10 pins together Any Solution For these point how to set zoom lever, Camera level to show all 10 pins on map view When i search for these point i found these code but i cant able to understand how to use these code.
CGFloat latDelta = rand()*0.125/RAND_MAX - 0.02;
CGFloat lonDelta = rand()*0.130/RAND_MAX - 0.08;
CGFloat lat = 59.189358;
CGFloat lng = 18.267839;
CLLocationCoordinate2D newCoord = {lat+latDelta, lng+lonDelta};
DTSAnnotation *annotation = [DTSAnnotation annotationWithCoord:newCoord];
Please Help me for solving these Two point to Related map Thankyou
Upvotes: 1
Views: 765
Reputation: 1
Regarding first point I had the same issue with that. The mistake is in that line of code pinView!.superview!.bringSubviewToFront(view)
.
As you want bring to the front pinView you have to do like this pinView!.superview!.bringSubviewToFront(pinView)
.
Because you taking superview of pinView and have to set that pinView to front. For me it's working.
Upvotes: 0