重新定位法律标签(MKAttributionLabel) [英] Reposition legal label ( MKAttributionLabel )
问题描述
我想将Legal标签移动到右侧.在iOS 6和7上,以下解决方案工作正常,但是在iOS 8.3上似乎无效.
I'd want to move the Legal label to the right side. On iOS 6 and 7 the below solution was working fine, however on iOS 8.3 it seems to not work.
我得到标签,然后在viewDidLayoutSubviews
中使用计时器(0.1秒)调用此方法:
I get the label, then with a timer (0.1 sec) in viewDidLayoutSubviews
I call this method :
-(void)moveLegalLabel
{
UIView * legalLink = [self attributionView];
legalLink.frame = CGRectMake(self.mapView.frame.size.width - legalLink.frame.size.width - 10, self.mapView.frame.size.height - legalLink.frame.size.height - 10 , legalLink.frame.size.width, legalLink.frame.size.height);
legalLink.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;
}
非常适合旋转等
但是,一旦我滚动地图,标签就会跳回到左侧.
试图在regionDidChangeAnimated
中调用此方法,但是标签首先从左跳然后向右跳,这真令人讨厌...
which works nicely for rotation, etc.
But as soon as I scroll the map, the label jumps back to the left.
Tried to call this method in the regionDidChangeAnimated
but the label jumps back first to the left then to right, it's really annoying...
我怎么能迫使那个愚蠢的标签留在右边?
How could I force that stupid label to stay on the right side ?
克里斯蒂安建议的解决方案:
- 子类化MKMapView
- 在其中移动
moveLegalLabel
代码 - 在
layoutSubviews
中调用
- Subclass the MKMapView
- Move the
moveLegalLabel
code there - Call it in
layoutSubviews
-(void)layoutSubviews
{
[super layoutSubviews];
[self moveLegalLabel];
}
-(void)layoutSubviews
{
[super layoutSubviews];
[self moveLegalLabel];
}
推荐答案
像-viewDidAppear:
,-mapView:regionWillChangeAnimated:
或-mapView:regionDidChangeAnimated:
这样的钩子,如建议的其他钩子,都不适合于此目的.
Hooks like -viewDidAppear:
, -mapView:regionWillChangeAnimated:
or -mapView:regionDidChangeAnimated:
, like others suggested, are not suited for this purpose.
最好的选择是将MKMapView
子类化,并在 调用super
之后在-layoutSubviews
中布置标签.
You best bet would be to subclass MKMapView
and layout your label in -layoutSubviews
after calling super
.
这篇关于重新定位法律标签(MKAttributionLabel)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!