Today, a strange problem is encountered, as follows:
In the rootviewcontroller of the navigation bar controller, a Uitextview control is added with the following code:
-(void) Viewdidload {
[Super viewdidload];
Self. title =@ "Test";
uitextview *textview = [[uitextviewalloc]init];
TextView. frame = CGRectMake(ten, +, +) ;
TextView. backgroundcolor = [uicolorgreencolor];
TextView. layer. Cornerradius =5;
TextView. layer. maskstobounds =YES;
TextView. Font =[uifontboldsystemfontofsize:];
[Self. View addsubview: TextView];
}
The results are as follows:
Then the problem arises, the cursor appears in the middle, it is clear that the height of the navigation bar and the cursor distance uitextview the top distance is the same
Make the following changes to the code to solve the problem:
-(void) Viewdidload {
[Super viewdidload];
Self. title =@ "Test";
//before adding uitextview , add a UIView
[self. View addsubview: [UIViewnew]];
uitextview *textview = [[uitextviewalloc]init];
TextView. frame = CGRectMake(ten, +, +) ;
TextView. backgroundcolor = [uicolorgreencolor];
TextView. layer. Cornerradius =5;
TextView. layer. maskstobounds =YES;
TextView. Font =[uifontboldsystemfontofsize:];
[Self. View addsubview: TextView];
}
The results are as follows:
This shows: Before adding the Uitextview control in the viewcontroller of the navigation bar, you need to add a uiview, otherwise the cursor will move down one (navigation bar + status bar) height.
I do not know why this is the reason, please advise us.
Add Uitextview control bug in the navigation bar of iOS