1. Application Scenario--Tabbar view of custom Uitabbarcontroller
(1) Hide Tabbar view
Generally we choose to customize the Tabbar view in two ways. 1 is to hide the Tabbar view, 2 is to remove the Tabbar view from the parent view, the code is as follows (assuming that the Uitabbarcontroller subclass was created):
-(void) Viewdidload {
Hide View
Self.tabBar.hidden = YES;
Or remove the Tabbar view directly
[Self.tabbar Removefromsuperview];
}
When the above code is executed, the Tabbar view disappears, showing the space occupied before the Tabbar view, as shown ():
After that, we'll add the custom Tabbar view to this blank position, where the height of the space is 49. Therefore our custom Tabbar view height should also be 49, otherwise there will be gap.
Sometimes, however, our custom Tabbar view height is not necessarily 49 high. So that is to say, we need to adjust the purple page height.
(2) Adjusting the view
Before we adjust the view, we need to look at the view of Tabbarcontroller, including which sub-views, the code is as follows:
For (UIView *subview in self.view.subviews) {
The self here refers to the Tabbarcontroller object.
NSLog (@ "Subview:%@", Subview);
}
The results are printed through the console:
Subview: >
Subview: >
From the printed results we can see that the Tabbarcontroller view contains 2 sub-views, one of which we are very familiar with the Uitabbar view, and you may take a closer look at its frame (especially the height). The two outer views are named Uitransitionview objects. In fact, when we create a Tabbarcontroller controller, it will automatically add 2 sub-views when requesting its own view, one is the Tabbar view we are very familiar with and the other is Uitransitionview. The role of the Tabbar view is self-evident, switching the view controller. The Uitranstionview view is used to host the content we are interested in (indirectly loading the child views of other view controllers). This is the purple part of Figure 2-1. Therefore, if we want to control the height of the custom Tabbar view (not a fixed 49), we need to lengthen the uitransitionview height, that is, to lengthen the purple view. So again, the problem is that we need to pinpoint the uitransitionview when we traverse the sub-view, and then modify its height so that reflection comes in handy. The code looks like this:
For (UIView *subview in self.view.subviews) {
Nsclassfromstring (), the reflection mechanism, by specifying the class name
Class class = Nsclassfromstring (@ "Uitransitionview");
Whether it belongs to the class
if ([Subview Ismemberofclass:class]) {
Increase the height of the Transitionview object by 9
When customizing the Tabbar view, the height can be set to 40
Subview.frame = CGRectMake (0, 0, 320, 519+9);
}
}
iOS development--using the reflection mechanism skillfully