【问题标题】:MKMapView in iOS 7iOS 7 中的 MKMapView
【发布时间】:2013-12-09 20:54:28
【问题描述】:

我在 iOS7 中遇到了 MKMapView 的问题,我一直在 iOS5 上使用它并且工作完美(至少我正在尝试做的)。

我的问题是 .userTrackingMode 在 iOS7 中不起作用。一直在寻找答案,但没有找到任何答案。

我想显示用户位置,它适用于 .showsUserLocation。但是当我想跟踪它时,它就像忽略它一样。有人有解决办法吗?

这就是我在 iOS 5 中的写法:

mMapView.showsUserLocation = YES;

mMapView.userTrackingMode = YES;

mMapView.userInteractionEnabled = NO;

据我所知,升级中的代码没有任何变化。

编辑:

不知道为什么,我用过 [self.mapView setUserTrackingMode:MKUserTrackingModeFollow 动画:YES]; 在每次位置更改时更改标签的方法中。然后它的工作。

不知道为什么我在 viewDidLoad 中声明它不起作用...?

【问题讨论】:

    标签: ios objective-c ios7 mkmapview mkusertrackingmode


    【解决方案1】:

    Welp,in Apple's documentation for MKMapView, ".userTrackingMode" 不是 BOOL,而是“enum”(整数)属性:

    typedef enum : NSInteger {
       MKUserTrackingModeNone = 0,
       MKUserTrackingModeFollow,
       MKUserTrackingModeFollowWithHeading,
    } MKUserTrackingMode;
    

    也许您设置错误可能是问题的一部分?

    另外,最好的设置方法是通过这个 API:

    - (void)setUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated(我已经为您链接了 Apple 文档)。那里有一个有用的“animated”参数。

    【讨论】:

    • Ops 忘了提到这一点。我尝试使用 ...ModeFollow 和 ModeFollowWithHeading。他们都没有工作:(
    • 要试试你写的第二件事
    • [self.mapView setUserTrackingMode:MKUserTrackingModeFollow Animation:YES];结果还是一样:
    • 啊,所以它现在对你有用(通过使用“setUserTrackingMode:animated:”?)。查看您的问题编辑,听起来我的回答确实对您有所帮助!
    • 是的,它成功了!认为不可能从 viewDidLoad 中使用它,以任何其他方法工作:) Thx
    猜你喜欢
    • 2013-10-02
    • 2013-12-06
    • 1970-01-01
    • 1970-01-01
    • 2014-03-03
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多