iOS自帶的返回按鈕有些坑,總是到達(dá)不到左邊,領(lǐng)導(dǎo)點(diǎn)了以后就一直bb,然后照著網(wǎng)上的代碼搞,添加一個(gè)空的item把寬度設(shè)為-10,代碼如下
[backButton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSpacer.width = -50; //我都偏移50了,還是不行
viewController.navigationItem.leftBarButtonItems = @[ negativeSpacer, [[UIBarButtonItem alloc] initWithCustomView:backButton] ];
記得以前是好使的最近一直有問(wèn)題,后來(lái)對(duì)比發(fā)現(xiàn)iOS11的導(dǎo)航欄結(jié)構(gòu)改了,
iOS11的:
BEE05BB4-6F2B-4BB9-A0F8-8166C028BBE8.png
多了一個(gè)在iOS9出現(xiàn)的那個(gè)盒子StackView
iOS10的:由于偏移50都超過(guò)屏幕了,
110F84DD-405F-4109-8961-60078759A6CF.png
結(jié)論:
使用偏移本來(lái)是可以的,但是iOS11導(dǎo)航欄把item放進(jìn)盒子里面,不管你偏移多少左邊始終有大概20的距離,偏移方法失效
解決方案:
https://github.com/zhangkun0625/UINavigation-SXFixSpace