Str*_*ers 23 cocoa-touch mkmapview ios swift
有谁知道在MKMapview中改变指南针位置的方法?
我说的是当地图旋转时显示在地图右上角的指南针.
我正在制作它,因此您可以看到导航栏下方的地图模糊,这意味着框架的y原点将位于导航栏下方.问题是,当地图旋转时,它会自动在右上角添加指南针按钮,您可以(如此)在下面的屏幕截图中看到,这是由navBar覆盖的.
我还没有看到任何关于指南针的文件,有人有什么想法吗?
Kla*_*aas 17
我的测试表明,它以MKMapView
某种方式知道它在什么情况下显示.如果您使用常规UINavigationController
,即使它是半透明的,您也会将指南针放在导航栏下方.
UIViewController
iOS 7中有一个新属性,用于定义Y轴上实际内容的开头.它被称为topLayoutGuide
.
遗憾的是,你无法真正影响Apple用于在不同内容中计算此属性的价值.它还取决于状态栏的可见性.
但是:为了解决这个问题,我创建了一个简单的自定义对象,我在自定义视图控制器中返回:
@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
Run Code Online (Sandbox Code Playgroud)
然后我在我的UIViewController
子类中覆盖了以下两个方法:
- (id<UILayoutSupport>)topLayoutGuide {
return [[MiFixedLayoutGuide alloc]initWithLength:44];
}
- (id<UILayoutSupport>)bottomLayoutGuide {
return [[MiFixedLayoutGuide alloc]initWithLength:44];
}
Run Code Online (Sandbox Code Playgroud)
这使布局指南插入了44个点.并且MKMapView
将使用这些值将罗盘定位在顶部,并在底部使用"Legal"标签.
您现在必须注意的一件事是,您无法在自动布局可视化格式语言中使用布局指南.
Mon*_*ono 16
使用iOS 8,您可以轻松完成:
[someMapView setLayoutMargins:UIEdgeInsetsMake(20, 0, 20, 0)];
Run Code Online (Sandbox Code Playgroud)
迅速:
mapView.layoutMargins = UIEdgeInsets(top: 20, left: 0, bottom: 20, right: 0)
Run Code Online (Sandbox Code Playgroud)
在这里,您可以计算UI元素的高度而不是20,而不是20,以针对每个设备或元素具有更动态的解决方案。
归档时间: |
|
查看次数: |
5927 次 |
最近记录: |