如何在UINavigation和UITabBar

时间:2018-04-26 15:16:50

标签: ios objective-c uitabbarcontroller uinavigationbar overlay

我想在底部的现有UINavigationBar和UITabBar项目之上显示一个过度的视图。

我尝试直接在应用程序窗口中添加叠加视图的视图,但不会有任何想法。

这是我的所有约束的自定义视图

-(void)showView{
    animationOverlay=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 400, 400)];
    animationOverlay.translatesAutoresizingMaskIntoConstraints=false;

    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setFrame:CGRectMake(0, 0, 100, 100)];
    [btn setTitle:@"Go" forState:UIControlStateNormal];
    [btn setTranslatesAutoresizingMaskIntoConstraints:false];

    [animationOverlay setBackgroundColor:[UIColor redColor]];

    NSLayoutConstraint *leftConstraint = [NSLayoutConstraint
                                          constraintWithItem:animationOverlay attribute:NSLayoutAttributeLeft
                                          relatedBy:NSLayoutRelationEqual toItem:self.view attribute:
                                          NSLayoutAttributeLeft multiplier:1.0 constant:0];

    NSLayoutConstraint *rightConstraint = [NSLayoutConstraint
                                           constraintWithItem:animationOverlay attribute:NSLayoutAttributeWidth
                                           relatedBy:NSLayoutRelationEqual toItem:self.view attribute:
                                           NSLayoutAttributeWidth multiplier:1.0 constant:0];

    NSLayoutConstraint *topConstraint = [NSLayoutConstraint
                                         constraintWithItem:animationOverlay attribute:NSLayoutAttributeTop
                                         relatedBy:NSLayoutRelationEqual toItem:self.view attribute:
                                         NSLayoutAttributeTop multiplier:1.0 constant:0];

    NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint
                                            constraintWithItem:animationOverlay attribute:NSLayoutAttributeBottom
                                            relatedBy:NSLayoutRelationEqual toItem:self.view attribute:
                                            NSLayoutAttributeBottom multiplier:1.0 constant:0];

    NSLayoutConstraint *centreXConstraint= [NSLayoutConstraint constraintWithItem:btn
                                                                        attribute:NSLayoutAttributeCenterX
                                                                        relatedBy:0
                                                                           toItem:animationOverlay
                                                                        attribute:NSLayoutAttributeCenterX
                                                                       multiplier:1
                                                                         constant:0];

    NSLayoutConstraint *centreYConstraint= [NSLayoutConstraint constraintWithItem:btn
                                                                        attribute:NSLayoutAttributeCenterY
                                                                        relatedBy:0
                                                                           toItem:animationOverlay
                                                                        attribute:NSLayoutAttributeCenterY
                                                                       multiplier:1
                                                                         constant:0];

    [self.view addSubview:animationOverlay];
    [self.view addConstraint:leftConstraint];
    [self.view addConstraint:rightConstraint];
    [self.view addConstraint:topConstraint];
    [self.view addConstraint:bottomConstraint];
    [animationOverlay addSubview:btn];
    [self.view addConstraint:centreXConstraint];
    [self.view addConstraint:centreYConstraint];

}

-(void)hideView{
    [animationOverlay removeFromSuperview];
} 

enter image description here

现在我可以在ViewController的视图中成功完成此操作

关于如何做到这一点的任何想法..

在不违反约束的情况下,我无法想办法如何做到这一点

任何想法,欢迎提出建议

1 个答案:

答案 0 :(得分:0)

您是否尝试以模态方式显示VC,我认为这将涵盖标签栏和导航栏:

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion;

将覆盖视图放在另一个VC中,然后使用presentViewController:

从当前VC中显示该VC