简体   繁体   English

iOS 7中的MKMapView

[英]MKMapView in iOS 7

I have a problem with MKMapView in iOS7, I have been using it with iOS5 and worked flawless (at least what Im trying to do). 我在iOS7中遇到了MKMapView问题,我一直在将它与iOS5一起使用并且可以完美地工作(至少Im试图这样做)。

Well my problem is that .userTrackingMode won't work in iOS7. 好吧,我的问题是.userTrackingMode在iOS7中不起作用。 Been searching for an answer but haven't found any. 一直在寻找答案,但未找到任何答案。

I want to show user location, it work fine with .showsUserLocation. 我想显示用户位置,可以与.showsUserLocation一起正常使用。 But when I want to track it its like it just ignores it. 但是,当我要跟踪它时,就忽略它。 Anyone have a fix? 有人解决吗?

This is how I wrote it in iOS 5: 这是我在iOS 5中编写的方式:

mMapView.showsUserLocation = YES;

mMapView.userTrackingMode = YES;

mMapView.userInteractionEnabled = NO;

And what I know there wasn't any changes with the code in the upgrade. 而且我知道升级中的代码没有任何变化。

EDIT: 编辑:

Don't know why but I used [self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES]; 不知道为什么,但是我用了[self.mapView setUserTrackingMode:MKUserTrackingModeFollow animation:YES]; inside a method that change a label every time that the location change. 在每次位置更改时都会更改标签的方法中。 Then its working. 然后它的工作。

Don't know why it's not working when I declare it in viewDidLoad... ? 不知道为什么我在viewDidLoad ...中声明它时不起作用?

Welp, in Apple's documentation for MKMapView, " .userTrackingMode " is not a BOOL but instead it's an " enum " (Integer) property: 在苹果公司针对MKMapView的文档中, .userTrackingMode表示.userTrackingMode不是BOOL,而是“ enum ”(整数)属性:

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

Maybe you're setting it wrongly could be part of the problem? 也许您设置错误可能是问题的一部分?

Also, the best way to set it is via this API: 另外,最好的设置方法是通过以下API:

- (void)setUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated (I've linked the Apple documentation for you). - (void)setUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated (我已经为您链接了Apple文档)。 There's a useful " animated " argument there. 那里有一个有用的“ animated ”参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM