除了tabViewController中的标签栏之外,如何将所有视图向下移动?

时间:2015-06-02 08:13:42

标签: ios objective-c uitabbarcontroller uinavigationbar

为了解决iOS 7+中状态栏和导航栏的重叠问题,我在Paint mPaint; mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT); didFinishLaunchingWithOptions内的AppDelegate.m内使用此代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    //some codes
    //.
    //.

    if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
    {
        UIView *FakeNavBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
        FakeNavBar.backgroundColor = UIColorFromRGB(0x55BCAFF);

        float navBarHeight = 20.0;
        for (UIView *subView in self.window.subviews) {

            if ([subView isKindOfClass:[UIScrollView class]]) {
                subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y + navBarHeight, subView.frame.size.width, subView.frame.size.height - navBarHeight);
            } else {
                subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y + navBarHeight, subView.frame.size.width, subView.frame.size.height);
            }
        }
        [self.window addSubview:FakeNavBar];
    }
}

它将我的所有控制器和视图向下推20像素并且重叠问题得到修复但是当我到达我的标签视图控制器场景时,底部的标签栏超出视图20像素。

那么我怎样才能将标签栏保持在原位,同时将其他所有内容都移开?

如果我只能将标签栏向上移动20个像素,那也可以。

3 个答案:

答案 0 :(得分:1)

我只能将标签栏向上移动20个像素,但这可能会在标签栏后面放置一些不需要的视图。

这是我在UITabBarController类的viewDidAppear内编写的代码:

-(void)viewDidAppear:(BOOL)animated{
    CGRect newFrame = self.tabBar.frame;
    newFrame.origin.y -= 20;
    self.tabBar.frame = newFrame;
}

答案 1 :(得分:0)

请使用以下代码 -

if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
    {
        UIView *FakeNavBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
        FakeNavBar.backgroundColor = UIColorFromRGB(0x55BCAFF);

        float navBarHeight = 20.0;
        for (UIView *subView in self.window.subviews) {

            for (int index=0; index<[tabBarController.viewControllers count]; index++)
            {

                 if ([subView isKindOfClass:[[(UIViewController*)[tabBarController.viewControllers objectAtIndex:index] view] class]])
                 {
                     continue;
                 }
            }

            if ([subView isKindOfClass:[UIScrollView class]]) {
                subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y + navBarHeight, subView.frame.size.width, subView.frame.size.height - navBarHeight);
            } else {
                subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y + navBarHeight, subView.frame.size.width, subView.frame.size.height);
            }
        }
        [self.window addSubview:FakeNavBar];
    }

答案 2 :(得分:0)

我认为您没有使用导航控制器,并且您已在视图中手动添加了导航栏。是吗?

您应该能够通过在故事板中添加视图控制器视图顶部状态栏大小的视图来实现您的目标。

您使用的是自动布局限制吗?您可以使用它们使这些视图粘贴到视图的顶部,具有20像素的固定高度和宽度等于视图控制器视图的宽度。