检查用户位置是否在地图iphone上可见 [英] Check if user location is visible on map iphone
问题描述
我想隐藏或显示UIButton天气用户的当前位置在地图上可见。在测试代码xcode时,我可以看到meassage 用户位置视图不可见但应该是。在didUpdateLocation方法中的控制台上显示....
如果用户位置是在地图上看不到。如何在我的情况下使用此消息生成事件以隐藏或显示UIButton?
感谢您提前获得任何帮助。
I want to hide or show a UIButton weather user's current location is visible on map. While testing the code xcode I can see meassage "User location view is NOT visible but should be. Showing...."
on console in "didUpdateLocation" method if users location is not visible on map. How can I use this message to generate events in my case to hide or show a UIButton?
Thanks for any help in advance.
推荐答案
如果您想知道当前是否包含用户位置显示的地图区域,您可以在 regionDidChangeAnimated
委托方法中检查 userLocationVisible
属性:
If you want to know whether the user location is contained in the currently displayed map region, you can check the userLocationVisible
property in the regionDidChangeAnimated
delegate method:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
someButton.hidden = !mapView.userLocationVisible;
}
如果您只是想知道用户位置当前是否有值(是否它是否可见以及showsUserLocation是否打开),然后:
If you just want to know whether the user location currently has a value (whether it's visible or not and whether showsUserLocation is on or not), then:
if (mapView.userLocation.location == nil)
NSLog(@"user location not obtained yet");
else
NSLog(@"user location available (may or may not be currently visible)"):
这篇关于检查用户位置是否在地图iphone上可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!