【问题标题】:Auto resize mask for custom view in tab bar view controller not working标签栏视图控制器中自定义视图的自动调整大小掩码不起作用
【发布时间】:2012-11-05 16:25:57
【问题描述】:

我在标签栏视图控制器中有一个自定义视图。我已经为自定义视图设置了自动调整大小掩码,但它没有在 iphone 5 屏幕上对齐。在 iphone 4 屏幕上看起来不错。我在标签栏视图控制器的视图中确实加载了此代码。

self.customBadge = [CustomBadge customBadgeWithString:[AppGlobals sharedInstance].badgeNumber];


     self.customBadge.frame = CGRectMake(165, 420,  self.customBadge.frame.size.width,  self.customBadge.frame.size.width);
    self.customBadge.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
    [self.view addSubview: self.customBadge];

【问题讨论】:

    标签: ios6 autoresize


    【解决方案1】:

    您似乎正在根据 TabBar 的整个视图(大多数屏幕)添加带有坐标的徽章

    试试:

    1. 将徽章添加为标签栏视图本身的子视图(您可能希望将框架的 Y 从 420 降低到大约 5-10):

      [self.tabBar addSubview:self.customBadge];

    2. 如果 (1) 不适合您,您可以尝试硬编码 y 值(这是不好的做法,但如果您遇到困难 - 它应该可以):

      #define VALUE_BY_SCREEN_HEIGHT(regular, longScreen) (([[UIScreen mainScreen] bounds].size.height <= 480.0) ? regular : longScreen)

      ...

      self.customBadge.frame = CGRectMake(165, VALUE_BY_SCREEN_HEIGHT(420,508), self.customBadge.frame.size.width, self.customBadge.frame.size.width);

    【讨论】:

      猜你喜欢
      • 2020-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多