当您单击选择针脚图时出现的按钮(带字母" i"的圆圈)时,我如何发声?现在,配音,说"按钮"但我希望他说"信息"
导入UIKit 导入MapKit 导入AddressBookUI
类MapController:UIViewController,MKMapViewDelegate,MapManagerDelegate {
// MARK: - Outlet
@IBOutlet var myMap: MKMapView!
@IBOutlet var activityIndicator: UIActivityIndicatorView!
// MARK: - Metodi standard del controller
override func viewDidLoad() {
super.viewDidLoad()
// NSLocalizedString legge la chiave dai file Localizable.strings
// fa tutto in automatico in base alla lingua di iOS
// se la lingua non c'è (esmepio iOS è in francese, ma il francese non 'cè) l'App usa Base
// quindi la traduzione che metti nell'Inglese che deve essere uguale a quella di Base
// l'Inglese deve essere la lingua base che carica quando non trova una certa lingua
title = NSLocalizedString("APPTITLE", comment: "")
myMap.delegate = self
myMap.userTrackingMode = MKUserTrackingMode.Follow
MapManager.sharedInstance.delegate = self
MapManager.sharedInstance.controller = self
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
myMap.removeAnnotations(myMap.annotations)
MapManager.sharedInstance.findLocation = false
MapManager.sharedInstance.startUpdateLocation()
activityIndicator.startAnimating()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent
}
// MARK: - Delegati
//MapManagerDelegate
func incomingUserLocation(region: MKCoordinateRegion) {
//println("incomingUserLocation")
myMap.setRegion(region, animated: false)
MapManager.sharedInstance.currentMap = myMap
MapManager.sharedInstance.searchPoiWithName("farmacia")
// I punti di interesse funzionano indipendentemente dalla lingua
// quindi lascia pharmacy, ovvero farmacia in inglese
}
func incomingPin(pin: Pin) {
//println("pin!")
myMap.addAnnotation(pin)
}
func didFinishSearchPoi() {
//println("didFinishSearchPoi")
MapManager.sharedInstance.stopUpdateLocation()
MapManager.sharedInstance.findLocation = false
activityIndicator.stopAnimating()
}
func incomingError(error: NSError) {
print("error: \(error)")
MapManager.sharedInstance.stopUpdateLocation()
MapManager.sharedInstance.findLocation = false
activityIndicator.stopAnimating()
}
//MKMapViewDelegate
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let annView : MKPinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "currentloc")
annView.pinTintColor = UIColor(red: 0/255, green: 229/255, blue: 17/255, alpha: 1.0)
annView.animatesDrop = true
annView.canShowCallout = true
annView.calloutOffset = CGPointMake(-8, 0)
annView.autoresizesSubviews = true
annView.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure) as UIView
return annView
}
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
var pin = view.annotation as! Pin
func apriMappe(action : UIAlertAction!) {
let endLocation = MKPlacemark(coordinate: view.annotation!.coordinate, addressDictionary: nil)
let endItem = MKMapItem(placemark: endLocation)
endItem.name = view.annotation!.title!
let opzioniLancio = [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving]
endItem.openInMapsWithLaunchOptions(opzioniLancio)
}
func telefona(action : UIAlertAction!) {
let cutSpace = pin.phone.stringByReplacingOccurrencesOfString("\\s",
withString: "",
options: NSStringCompareOptions.RegularExpressionSearch,
range: nil)
let cutInter = (cutSpace as NSString).substringFromIndex(4)
let phone = "tel://" + cutInter
print(phone)
if let url = NSURL(string: phone) {
UIApplication.sharedApplication().openURL(url)
}
}
let myActionSheet = UIAlertController(title: NSLocalizedString("PRIMAVOCEMENU", comment: ""),
message: nil,
preferredStyle: UIAlertControllerStyle.ActionSheet)
myActionSheet.addAction(UIAlertAction(title: NSLocalizedString("SECONDAVOCEMENU", comment: ""),
style: UIAlertActionStyle.Default,
handler: telefona))
myActionSheet.addAction(UIAlertAction(title: NSLocalizedString("TERZAVOCEMENU", comment: ""),
style: UIAlertActionStyle.Default,
handler: apriMappe))
myActionSheet.addAction(UIAlertAction(title: NSLocalizedString("QUARTAVOCEMENU", comment: ""),
style: UIAlertActionStyle.Cancel,
handler: nil))
self.presentViewController(myActionSheet, animated: true, completion: nil)
}
// MARK: - Azioni
@IBAction func ricarica(sender: UIBarButtonItem) {
//println("ricarica")
myMap.removeAnnotations(myMap.annotations)
MapManager.sharedInstance.findLocation = false
MapManager.sharedInstance.startUpdateLocation()
activityIndicator.startAnimating()
}
}
import UIKit
导入MapKit 导入AddressBookUI
类MapController:UIViewController,MKMapViewDelegate,MapManagerDelegate {
// MARK: - Outlet
@IBOutlet var myMap: MKMapView!
@IBOutlet var activityIndicator: UIActivityIndicatorView!
// MARK: - Metodi standard del controller
override func viewDidLoad() {
super.viewDidLoad()
// NSLocalizedString legge la chiave dai file Localizable.strings
// fa tutto in automatico in base alla lingua di iOS
// se la lingua non c'è (esmepio iOS è in francese, ma il francese non 'cè) l'App usa Base
// quindi la traduzione che metti nell'Inglese che deve essere uguale a quella di Base
// l'Inglese deve essere la lingua base che carica quando non trova una certa lingua
title = NSLocalizedString("APPTITLE", comment: "")
myMap.delegate = self
myMap.userTrackingMode = MKUserTrackingMode.Follow
MapManager.sharedInstance.delegate = self
MapManager.sharedInstance.controller = self
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
myMap.removeAnnotations(myMap.annotations)
MapManager.sharedInstance.findLocation = false
MapManager.sharedInstance.startUpdateLocation()
activityIndicator.startAnimating()
}
func pushAViewController() {
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent
}
// MARK: - Delegati
//MapManagerDelegate
func incomingUserLocation(region: MKCoordinateRegion) {
//println("incomingUserLocation")
myMap.setRegion(region, animated: false)
MapManager.sharedInstance.currentMap = myMap
MapManager.sharedInstance.searchPoiWithName("farmacia")
// I punti di interesse funzionano indipendentemente dalla lingua
// quindi lascia pharmacy, ovvero farmacia in inglese
}
func incomingPin(pin: Pin) {
//println("pin!")
myMap.addAnnotation(pin)
}
func didFinishSearchPoi() {
//println("didFinishSearchPoi")
MapManager.sharedInstance.stopUpdateLocation()
MapManager.sharedInstance.findLocation = false
activityIndicator.stopAnimating()
}
func incomingError(error: NSError) {
print("error: \(error)")
MapManager.sharedInstance.stopUpdateLocation()
MapManager.sharedInstance.findLocation = false
activityIndicator.stopAnimating()
}
//MKMapViewDelegate
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let annView : MKPinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "currentloc")
annView.pinTintColor = UIColor(red: 0/255, green: 229/255, blue: 17/255, alpha: 1.0)
annView.animatesDrop = true
annView.canShowCallout = true
annView.calloutOffset = CGPointMake(-8, 0)
annView.autoresizesSubviews = true
let button: UIButton = UIButton(type: .DetailDisclosure)
button.addTarget(self, action: "pushAViewController:", forControlEvents: .TouchDown)
annView.rightCalloutAccessoryView = button
button.accessibilityLabel="Informazioni"
return annView
}
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
var pin = view.annotation as! Pin
func apriMappe(action : UIAlertAction!) {
let endLocation = MKPlacemark(coordinate: view.annotation!.coordinate, addressDictionary: nil)
let endItem = MKMapItem(placemark: endLocation)
endItem.name = view.annotation!.title!
let opzioniLancio = [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving]
endItem.openInMapsWithLaunchOptions(opzioniLancio)
}
func telefona(action : UIAlertAction!) {
let cutSpace = pin.phone.stringByReplacingOccurrencesOfString("\\s",
withString: "",
options: NSStringCompareOptions.RegularExpressionSearch,
range: nil)
let cutInter = (cutSpace as NSString).substringFromIndex(4)
let phone = "tel://" + cutInter
print(phone)
if let url = NSURL(string: phone) {
UIApplication.sharedApplication().openURL(url)
}
}
let myActionSheet = UIAlertController(title: NSLocalizedString("PRIMAVOCEMENU", comment: ""),
message: nil,
preferredStyle: UIAlertControllerStyle.ActionSheet)
myActionSheet.addAction(UIAlertAction(title: NSLocalizedString("SECONDAVOCEMENU", comment: ""),
style: UIAlertActionStyle.Default,
handler: telefona))
myActionSheet.addAction(UIAlertAction(title: NSLocalizedString("TERZAVOCEMENU", comment: ""),
style: UIAlertActionStyle.Default,
handler: apriMappe))
myActionSheet.addAction(UIAlertAction(title: NSLocalizedString("QUARTAVOCEMENU", comment: ""),
style: UIAlertActionStyle.Cancel,
handler: nil))
self.presentViewController(myActionSheet, animated: true, completion: nil)
}
// MARK: - Azioni
@IBAction func ricarica(sender: UIBarButtonItem) {
//println("ricarica")
myMap.removeAnnotations(myMap.annotations)
MapManager.sharedInstance.findLocation = false
MapManager.sharedInstance.startUpdateLocation()
activityIndicator.startAnimating()
}
}
答案 0 :(得分:1)
您正在向rightCalloutAccessoryView添加一个按钮。声明按钮separetley,并将其引用到rightCalloutAccessoryView。
所以你的代码在这一行:
annView.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure) as UIView
将更改为:
var button: UIButton = UIButton(type: .DetailDisclosure)
button.addTarget(self, action: "yourMEthodName:", forControlEvents: .TouchUpInside)
annView.rightCalloutAccessoryView = button
现在您可以按如下方式更改按钮辅助功能特性:
button.accessibilityTraits=UIAccessibilityTraitStaticText
或
button.accessibilityTraits = .StaticText
并将按钮的可访问性LAbel更改为:
button.accessibilityLabel=@"Information"
当你点击它时,现在语音将会将按钮读作信息。
注意:按如下方式声明按钮目标方法:
func pushAViewController(sender:UIButton!)
{
print("Button Clicked")
}