UIViews ending up beneath tab bar

后端 未结 4 1591
没有蜡笔的小新
没有蜡笔的小新 2020-12-15 09:36

In my app, I aligned a label the standard amount from the bottomLayoutGuide using autolayout. When the app first starts everything is layed out as I wanted but when I switch

4条回答
  •  死守一世寂寞
    2020-12-15 10:27

    Calling setNeedsLayout is all that needs to be done. This essentially patches the framework bug. It needs to be called on the UITabBarController view itself when a new view is selected. Create a delegate for the app's tab bar controller. and put this in the delegate object:

    @interface MyPatch : NSObject 
    
    @end
    
    @implementation MyPatch
    
    -(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    {
        [tabBarController.view setNeedsLayout];
    }
    
    @end
    

    And initialize it wherever you want... something like this:

    @interface AppDelegate : UIResponder 
    {
             MyPatch *patch;
    
    }
    
    @end
    
    @implementation AppDelegate
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        patch=[MyPatch new];
        myTabBarController.delegate=patch;
    }
    
    @end
    

提交回复
热议问题