UISearchBar CGContext ERROR

后端 未结 4 1667
无人共我
无人共我 2020-12-24 04:46

I have a UISearchBar inside a view, whenever I tap on it, after the keyboard comes up -

after -(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar

4条回答
  •  一向
    一向 (楼主)
    2020-12-24 05:25

    It appears that the UISearchBar's AutoLayout constraints that are set in the .xib file are causing this problem. If there are any redundant or conflicting constraints that weren't caught by the compiler it can cause a drawing error and throw these errors.

    1. Go to the .xib file that has the UISearchBar
    2. Click on the UISearchBar and go to the Size Inspector (looks like a ruler, usually on the right side with the control's properties)
    3. One by one, click on each constraint and watch to see where they are - no two constraints should be measuring the same property. For example, on mine, I had one constraint measuring from the top of the control to the top of the view, and another constraint measuring from the bottom of the control to the top of the view.
    4. Remove any offending constraints, build, and run! If that doesn't work, you may want to check the constraints on the surrounding controls.

提交回复
热议问题