【问题标题】:How to resize an UITabBar selection indicator image in landscape如何在横向中调整 UITabBar 选择指示器图像的大小
【发布时间】:2015-06-16 09:33:44
【问题描述】:

我正在 UITabBarController 子类(“CustomTabBarVC”)中自定义 UITabBar。我想使用自定义选择指示器图像,所以我在“CustomTabBarVC”实现中写了这个:

- (void)viewWillLayoutSubviews
{
   CGFloat tabItemWidth;
   UIView *tabItem = [[[self.tabBar items] lastObject] view];
   tabItemWidth = tabItem.frame.size.width;

   UIImage *selectionIndicator;

   // Set here 'selectionIndicator' to an UIImage which fits 'tabItemWidth' and tab bar's height

   [[UITabBar appearance] setSelectionIndicatorImage:selectionIndicator];
}

当视图以纵向加载时,这可以正常工作,但是当我将设备的方向更改为横向时,虽然再次调用该方法并且selectionIndicator 图像似乎采用了新宽度,但它没有重绘并且以前的图像一直显示。我该怎么办?

谢谢

【问题讨论】:

    标签: ios uiimage uitabbarcontroller uitabbar uitabbaritem


    【解决方案1】:

    当您的设备方向发生变化时,将调用默认委托,并通过此方法获取您的方向。

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
     // do something before rotation 
    }
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
    {
     // do something after rotation
    }
    

    然后实现 viewWillAppear: 这个方法会在定向委托之后被调用。现在你可以用这个方法改变你的 TabBar 图片了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-29
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      • 1970-01-01
      • 2016-04-11
      • 2017-08-10
      • 2014-10-04
      相关资源
      最近更新 更多