移动端设计研发

UIImagePickerController 返回按钮下移的问

2018-03-11  本文已影响142人  Show_Perry

昨天有朋友遇到调用UIImagePickerController时返回按钮下移的问题。具体提示为:

[LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x604000095950 _UIModernBarButton:0x7ffe20c35250.bottom == UILayoutGuide:0x6040007a1260'UIViewLayoutMarginsGuide'.bottom + 64.6667   (active)>",
    "<NSLayoutConstraint:0x6040000959f0 V:[_UIModernBarButton:0x7ffe20c35250]-(>=0)-|   (active, names: '|':_UIButtonBarButton:0x7ffe20c345b0 )>",
    "<NSLayoutConstraint:0x604000095810 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x6040007a1260'UIViewLayoutMarginsGuide']-(16)-|   (active, names: '|':_UIButtonBarButton:0x7ffe20c345b0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x604000095950 _UIModernBarButton:0x7ffe20c35250.bottom == UILayoutGuide:0x6040007a1260'UIViewLayoutMarginsGuide'.bottom + 64.6667   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

昨晚帮他打UIViewAlertForUnsatisfiableConstraints断点查看层次结构也没看出是什么原因。早上起来,突然想到有可能是返回按钮自定义导致的,然后查看他的自定义地方。果然是这里原因。
他的自定义方法:

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)                                                   forBarMetrics:UIBarMetricsDefault];

个人不建议用这种方法来隐藏返回标题,可以变通下改变返回按钮字体例如:

 UIBarButtonItem *item = [UIBarButtonItem appearance];
 NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:0.001],NSForegroundColorAttributeName:[UIColor clearColor]};
 [item setTitleTextAttributes:attributes forState:UIControlStateNormal];

这种修改所有的UIBarButtonItem的方法会影响其他的UIBarButtonItem 刚有位朋友在下面留言询问后,我修改了下。新建一个基于UINavigationController的类添加下面代码,其他的UINavigationController都继承这个类。

- (void)viewDidLoad
{
    [super viewDidLoad];
    //去掉返回按钮文字
    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:0.001],NSForegroundColorAttributeName:[UIColor clearColor]};
    [self.navigationItem.backBarButtonItem setTitleTextAttributes:attributes forState:UIControlStateNormal];
}

注:升级系统至11.2.6 后此方法失效了!

做了个Demo测试改前:


屏幕快照 2018-03-11 上午10.55.17.png

修改后:


屏幕快照 2018-03-22 下午6.02.44.png
上一篇下一篇

猜你喜欢

热点阅读