iOS flutter 混编 tabBar 隐藏flutter 界面出现黑边

记录 问题

问题描述,

在UITabBarController 中加一个 flutter 界面,

flutter 界面跳转到二级页面,隐藏tabbar 

tabbar 位置出现黑色底边,flutter 页面不能全屏。

解决方法 :

自己的 controller 继承 FlutterViewController 

重写viewDidAppear方法

找到self.view 上的子控件,重设frame 

- (void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];

    self.tabBarController.tabBar.hidden = NO;

    NSArray *views = self.view.subviews;

    UIScrollView *scrollerView;

    for (UIView *view in views) {

        if ([view isKindOfClass:[UIScrollView class]]) {

            scrollerView = (UIScrollView *)view;

        }

    }

    self.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

    scrollerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

}

 

相关代码:

 

- (instancetype)init

{

    self = [super init];

    if (self) {

        [self setInitialRoute:@"home"];

        NSString *channelName = @"zhe li  sui yi xie";

        FlutterMethodChannel *methodChannel = [FlutterMethodChannel methodChannelWithName:channelName binaryMessenger:[self binaryMessenger]];

        NSString *eventName = @"zhe li  sui yi xie";

        self.eventChannel = [FlutterEventChannel eventChannelWithName:eventName binaryMessenger:[self binaryMessenger]];

        [self.eventChannel setStreamHandler:self];

        [methodChannel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult  _Nonnull result) {

            NSLog(@"method=%@ \narguments = %@", call.method, call.arguments);

            if ([call.method isEqualToString:@"scan"]) {

                NSLog(@"扫码");

            }

            if ([call.method isEqualToString:@"config"]) {

                NSDictionary *dic = @{@"baseURL":CommonURL,@"token":[kUserDefaults objectForKey:UserToken],@"themeType":@NO};

                result(dic);

            }

            if ([call.method isEqualToString:@"setToolBar"]) {

                BOOL hidden = call.arguments;

                if ([call.arguments isEqual:@"true"]) {

                    hidden = YES;

                }else{

                    hidden = NO;

                }

                self.tabBarController.tabBar.hidden  = hidden;

                result(@YES);

            }

            

            if ([call.method isEqualToString:@"logout"]) {

                NSLog(@"退出登录");

            }

        }];

    }

    return self;

}

你可能感兴趣的:(iOS,flutter)