Giter Club home page Giter Club logo

Comments (11)

spicyShrimp avatar spicyShrimp commented on September 25, 2024 1

给你个最简单的实现方式,全部使用button->customview 无论是图片或者文字
另外可以不做偏移,你完全可以叫UI切图片边缘透明的,甚至可以使用button自己扩展imageView的大小
button也可以直接使用titile 如果你有详细看demo的话 你会在cread中发现有针对title做处理

from ios-11-uinavigationitem-sxfixspace.

spicyShrimp avatar spicyShrimp commented on September 25, 2024

我这边直接使用demo运行时没有问题的 不会有16像素点无响应的情况,
不清楚你的具体实现状况是怎么样的,是否是按照此demo中的方法?
另外也还有新的方法
你可以参考https://github.com/spicyShrimp/UINavigation-SXFixSpace

from ios-11-uinavigationitem-sxfixspace.

su350380433 avatar su350380433 commented on September 25, 2024

补充下,应该不是16像素,是这个值 sx_defaultFixSpace 像素
我们是适配旧的工程,旧工程的写法是自定义的导航栏按钮
_leftNavButton = [[UIButton alloc] init];
[_leftNavButton setImage:[UIImage imageNamed:@"icon_return"] forState:UIControlStateNormal];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:_leftNavButton];
[self.navigationItem setLeftBarButtonItem:leftItem];

适配这种类型的代码,导航栏返回按钮的点击响应区域变小,而且距离左右边距会差 sx_defaultFixSpace 像素点击无反应。
大神有何高招吗

from ios-11-uinavigationitem-sxfixspace.

spicyShrimp avatar spicyShrimp commented on September 25, 2024

本demo中没有sx_defaultFixSpace这个属性值,你说的是https://github.com/spicyShrimp/UINavigation-SXFixSpace这个demo中的 我在该demo中设置的默认距离是8 ,你要是想没有间距,修改这个值为0就是了

from ios-11-uinavigationitem-sxfixspace.

su350380433 avatar su350380433 commented on September 25, 2024

大神:
是的,是在https://github.com/spicyShrimp/UINavigation-SXFixSpace这个demo里面,刚下了iOS-11-UINavigationItem-SXFixSpace这个Demo好像也没能解决我想要的问题。
适配旧项目的写法
1.UI展示间距左边距16像素,
2.点击响应区域变大

from ios-11-uinavigationitem-sxfixspace.

su350380433 avatar su350380433 commented on September 25, 2024

关于点击响应区域的问题,我想在UINavigationBar hitTest 来做,大神能不能帮忙看下这会有什么问题吗
@implementation UINavigationBar (RNFixSpace)

  • (UIView*)hitTest:(CGPoint) point withEvent:(UIEvent*) event
    {
    if (IOS11) {
    CGPoint tempPoint = point;
    if ((point.y < 45 && point.y > 0) &&
    (point.x < rn_defaultFixSpace || point.x > (self.width - rn_defaultFixSpace)))
    {
    if (point.x > rn_defaultFixSpace) {
    tempPoint = CGPointMake(point.x - rn_defaultFixSpace, point.y);
    }
    else{
    tempPoint = CGPointMake(point.x + rn_defaultFixSpace, point.y);
    }
    }
    return [super hitTest:tempPoint withEvent:event];
    }
    else{
    return [super hitTest:point withEvent:event];
    }
    }

from ios-11-uinavigationitem-sxfixspace.

spicyShrimp avatar spicyShrimp commented on September 25, 2024

你是既需要16的间距 还需要能够点击?
两种方案: 1.使用demo中的方式偏移16个像素 然后参考http://blog.csdn.net/spicyshrimp/article/details/76037251我的这个blog实现扩大点击16个像素
2.使用demo中的方式偏移0像素 然后使用button,将button里面的内容偏移16个像素,比如
button.contentInsert = ...

from ios-11-uinavigationitem-sxfixspace.

su350380433 avatar su350380433 commented on September 25, 2024

感谢大神的指点迷津
不过,在方案2中:UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:_leftNavButton];
不一定是initWithCustomView,也有可能是[[UIBarButtonItem alloc] initWithTitle:@"titile" (因为要适配旧项目各种的写法),所以button.contentInsert 不能全部解决吧。
方案1中:以上提到的,如果不是UIControl、或者UIView控件,扩大响应区域这种做法是无效的。
而且即使是UIControl或者UIView控件,点击左边小于16(point.x < 16)像素的区域也不会执行hitTest方法,因为在它的superView(_UITAMICAdaptorView)就被return,不在_UITAMICAdaptorView响应区域范围内。

from ios-11-uinavigationitem-sxfixspace.

su350380433 avatar su350380433 commented on September 25, 2024

我是菜鸟,不知道说的是否都对,有不对之处请大神不惜赐教啊😅

from ios-11-uinavigationitem-sxfixspace.

su350380433 avatar su350380433 commented on September 25, 2024

感谢大神,回复实在太快了。

from ios-11-uinavigationitem-sxfixspace.

spicyShrimp avatar spicyShrimp commented on September 25, 2024

你的需求无非就是图片元素留边16像素的问题, 你把默认间距变成0 使用button->customView ,然后要么是按钮弄大一点,保证文字和图片16像素 要么是设置内容偏移16像素..
无非就是两步,
第一步设置间距为0
第二步使用button或者自定义的view设置item..这样item百分百是贴边的,那么你怎么设置按钮的内容,怎么设置按钮的偏移都是很容易处理的,都是最基本最基本的方法

from ios-11-uinavigationitem-sxfixspace.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.