指南针在iOS6地图视图中放置或放置地图 [英] Compass placing or position in a map view post iOS6

查看:177
本文介绍了指南针在iOS6地图视图中放置或放置地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道在MKMapview中更改指南针放置的方法?



我说的是地图右上角旋转时显示的罗盘。



我正在做,所以你可以看到地图模糊在导航栏下面,这意味着框架的y原点将在导航栏下面。问题是,当地图旋转时,它会自动添加右上角的罗盘按钮,你可以(种)看到下面的屏幕截图,navBar覆盖。





我是'

解决方案

我的测试表明, MKMapView 以某种方式知道在什么上下文中显示。如果您使用常规的 UINavigationController ,您会得到位于导航栏下方的罗盘,即使它是半透明的。



在iOS 7中有一个新的 UIViewController 属性,它定义了Y轴上实际内容的开始。很遗憾,你不能真正地影响苹果用不同内容计算这个属性的值,因为它们被称为 topLayoutGuide



为了解决这个问题,我创建了一个简单的自定义对象,我返回我的自定义视图控制器:

  @interface MiFixedLayoutGuide:NSObject< UILayoutSupport> 
@property(nonatomic)CGFloat pbLength;
- (id)initWithLength:(CGFloat)length;
@end

@implementation MiFixedLayoutGuide

- (id)initWithLength:(CGFloat)length {
self = [super init];
if(self){
_pbLength = length;
}
return self;
}

- (CGFloat)length {
return _pbLength;
}

@end

UIViewController 子类中的方法:

   - (id< UILayoutSupport> topLayoutGuide {
return [[MiFixedLayoutGuide alloc] initWithLength:44];
}

- (id< UILayoutSupport>)bottomLayoutGuide {
return [[MiFixedLayoutGuide alloc] initWithLength:44];
}

这将布局指南插入44点。 MKMapView 将使用这些值将罗盘放置在顶部,并在底部显示法律标签。



现在你需要注意的一件事是,你不能在自动布局视觉格式语言中使用布局指南。


Does anyone know of a way to change the placing of the compass in MKMapview?

I'm talking about the compass that shows up in the upper right corner of the map when it's rotated.

I'm making it so you can see the map blurred underneath the navigation bar, which means the frame's y origin will be underneath the nav-bar. The problem is that when the map is rotated, it automatically adds the compass button in the upper right corner and as you can (kind of) see in the screenshot below, that's covered by the navBar.

I haven't seen any documentation talking about the the compass, anybody have any ideas?

解决方案

My tests have shown, that the MKMapView somehow knows in what context it is displayed. If you use a regular UINavigationController you'll get the compass positioned below the navigation bar even when it is translucent.

There is a new UIViewController property in iOS 7 that defines the beginning of the actual content on the Y axis. It is called topLayoutGuide.

Sadly you cannot really influence the value that Apple uses to calculate this property in different contents. It also depends on the visibility of the status bar.

BUT: To solve this problem, I created a simple custom object that I return in my custom view controller:

@interface MiFixedLayoutGuide : NSObject <UILayoutSupport>
@property (nonatomic) CGFloat pbLength;
- (id)initWithLength:(CGFloat)length;
@end

@implementation MiFixedLayoutGuide

- (id)initWithLength:(CGFloat)length {
    self = [super init];
    if (self) {
        _pbLength = length;
    }
    return self;
}

- (CGFloat)length {
    return _pbLength;
}

@end

Then I overrode the following two methods in my UIViewController subclass:

- (id<UILayoutSupport>)topLayoutGuide {
    return [[MiFixedLayoutGuide alloc]initWithLength:44];
}

- (id<UILayoutSupport>)bottomLayoutGuide {
    return [[MiFixedLayoutGuide alloc]initWithLength:44];
}

This insets the layout guides by 44 points. And the MKMapView will use these values to position the compass at the top, and the "Legal" label at the bottom.

One thing that you now have to pay attention to is, that you cannot use the layout guides anymore within the auto layout visual format language.

这篇关于指南针在iOS6地图视图中放置或放置地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆