重新定位法律标签(MKAttributionLabel) [英] Reposition legal label ( MKAttributionLabel )

查看:155
本文介绍了重新定位法律标签(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 ?

克里斯蒂安建议的解决方案:

  1. 子类化MKMapView
  2. 在其中移动moveLegalLabel代码
  3. layoutSubviews
  4. 中调用
  1. Subclass the MKMapView
  2. Move the moveLegalLabel code there
  3. 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屋!

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