iPhone 5上没有显示的地图注释

时间:2017-05-22 17:59:26

标签: ios swift mapkit mkannotation mkannotationview

所以我有一个非常奇怪的问题,无法弄清楚为什么这是一个问题。

基本上我创建了一个注释数组并将它们添加到地图中...简单! 当我在iPhone 6或更高版本(在真实设备和模拟器上)上运行我的代码时,注释会按照我的预期出现。

如果我在iPhone 5(真实设备或模拟器)上运行我的代码,则注释不会出现。它的代码完全相同!

然后我决定在日志中创建一个简单的打印语句"添加好友注释"确保调用func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?

令我惊讶的是,iPhone 5上面的任何东西都被称为没有问题,但是在iPhone 5上,它在添加MKUser注释时永远不会被调用。

我完全坚持这一点,并希望得到任何建议......谢谢。

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    if (annotation is MKUserLocation) {
        returnUserBadgeColour()
        print("ADDING USER ANNOTATION")
        userRiderView = MKAnnotationView(frame: CGRect(x: 0.0, y: 0.0, width: 40, height: 40))
        userRiderView.image = UIImage(named:"\(userHaloColour)")
        userRiderView.layer.masksToBounds = false
        userRiderView.layer.backgroundColor = UIColor.clear.cgColor
        userRiderView.clipsToBounds = false

        circle.image = UIImage(named:"\(userBadgeColour)")
        userRiderView.addSubview(circle)

        let userlabel = UILabel(frame: CGRect(x: 0, y: 0, width: 26, height: 22))
        userlabel.font = UIFont(name: "Oswald-Regular", size: 17.0)
        userlabel.textColor = UIColor.white
        userlabel.textAlignment = .center
        userlabel.text = initials
        userRiderView.addSubview(userlabel)
        userlabel.center = CGPoint(x: (userRiderView.frame.width)/2, y: (userRiderView.frame.height)/2)

        return userRiderView
    }

    else if (annotation is FriendsAnnotation) {
        print("ADDING FRIEND ANNOTATION")

        friendRiderView = MKAnnotationView(frame: CGRect(x: 0.0, y: 0.0, width: 40, height: 40))
        friendRiderView.image = UIImage(named:"\(userHaloColour)")
        friendRiderView.layer.masksToBounds = false
        friendRiderView.layer.backgroundColor = UIColor.red.cgColor

        let circle = UIImageView(frame: CGRect(x: 5.0, y: 5.0, width: 70, height: 70))
        let colour = (annotation as! FriendsAnnotation).friendColor
        circle.image = UIImage(named:"\(colour)")
        friendRiderView.addSubview(circle)

        let friendLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 26, height: 22))
        friendLabel.font = UIFont(name: "Oswald-Regular", size: 17)
        friendLabel.textColor = UIColor.white
        friendLabel.textAlignment = .center
        friendLabel.text = (annotation as! FriendsAnnotation).friendsInitialsA
        friendRiderView.addSubview(friendLabel)
        friendLabel.center = CGPoint(x: (friendRiderView.frame.width)/2, y: (friendRiderView.frame.height)/2)

        return friendRiderView
    }

    else {
        print("ADDING ANY ANNOTATION")
        let any: MKAnnotationView = MKAnnotationView ()
        return any
    }

0 个答案:

没有答案