iOS11NavigationItem偏移,iOS11适配问题,iOS11导航栏返回偏移,iOS11BarButtonItem偏移,Xcode9遇见的问题
来源:互联网 发布:js生成随机数不要 编辑:程序博客网 时间:2024/06/08 10:37
更新iOS 11之后,用xcode 9运行App,你会发现以下问题:
注意:此文章代码做了更新,对于item点击不灵敏问题,文章结尾写出了解决办法。
1、MJ刷新异常
2、tableView的section之间间距变大,空白区域
3、导航栏返回按钮偏移20像素
下面我逐个讲一下解决办法:
1、MJ刷新异常,上拉加载出现跳动刷新问题:MJ已经更新,解决了此bug
2、tableView的section之间间距变大问题:解决办法:初始化的时候增加以下代码
self.tableView.estimatedRowHeight =0;
self.tableView.estimatedSectionHeaderHeight =0;
self.tableView.estimatedSectionFooterHeight =0;
3、导航栏按钮偏移20像素问题:
解决办法:
楼主写的分类:UIViewController+BarButton
代码如下:
//左侧一个图片按钮的情况
- (void)addLeftBarButtonWithImage:(UIImage *)image action:(SEL)action
{
UIView *view = [[UIViewalloc]initWithFrame:CGRectMake(0,0,44,44)];
view.backgroundColor = [UIColorclearColor];
UIButton *firstButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
firstButton.frame = CGRectMake(0, 0, 44, 44);
[firstButton setImage:imageforState:UIControlStateNormal];
[firstButton addTarget:selfaction:actionforControlEvents:UIControlEventTouchUpInside];
firstButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;
[firstButton setImageEdgeInsets:UIEdgeInsetsMake(0,5 *kScreenWidth /375.0,0,0)];
UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItemalloc]initWithCustomView:firstButton];
self.navigationItem.leftBarButtonItem = leftBarButtonItem;
}
//右侧一个图片按钮的情况
- (void)addRightBarButtonWithFirstImage:(UIImage *)firstImage action:(SEL)action
{
UIView *view = [[UIViewalloc]initWithFrame:CGRectMake(0,0,44,44)];
view.backgroundColor = [UIColorclearColor];
UIButton *firstButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
firstButton.frame = CGRectMake(0, 0, 44, 44);
[firstButton setImage:firstImageforState:UIControlStateNormal];
[firstButton addTarget:selfaction:actionforControlEvents:UIControlEventTouchUpInside];
firstButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentRight;
[firstButton setImageEdgeInsets:UIEdgeInsetsMake(0,0,0,5 *kScreenWidth /375.0)];
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItemalloc]initWithCustomView:firstButton];
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
}
//右侧为文字item的情况
- (void)addRightBarButtonItemWithTitle:(NSString *)itemTitle action:(SEL)action
{
UIButton *rightbBarButton = [[UIButtonalloc]initWithFrame:CGRectMake(0,0,88,44)];
[rightbBarButton setTitle:itemTitleforState:(UIControlStateNormal)];
[rightbBarButton setTitleColor:kDarkOneColorforState:(UIControlStateNormal)];
rightbBarButton.titleLabel.font = [UIFontsystemFontOfSize:14];
[rightbBarButton addTarget:selfaction:actionforControlEvents:(UIControlEventTouchUpInside)];
rightbBarButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentRight;
[rightbBarButton setTitleEdgeInsets:UIEdgeInsetsMake(0,0,0,5 *kScreenWidth/375.0)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItemalloc]initWithCustomView:rightbBarButton];
}
//左侧为文字item的情况
- (void)addLeftBarButtonItemWithTitle:(NSString *)itemTitle action:(SEL)action
{
UIButton *leftbBarButton = [[UIButtonalloc]initWithFrame:CGRectMake(0,0,44,44)];
[leftbBarButton setTitle:itemTitleforState:(UIControlStateNormal)];
[leftbBarButton setTitleColor:kDarkOneColorforState:(UIControlStateNormal)];
leftbBarButton.titleLabel.font = [UIFontsystemFontOfSize:16];
[leftbBarButton addTarget:selfaction:actionforControlEvents:(UIControlEventTouchUpInside)];
leftbBarButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;
[leftbBarButton setTitleEdgeInsets:UIEdgeInsetsMake(0,5 *kScreenWidth/375.0,0,0)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItemalloc]initWithCustomView:leftbBarButton];
}
- (void)addRightTwoBarButtonsWithFirstImage:(UIImage *)firstImage firstAction:(SEL)firstAction secondImage:(UIImage *)secondImage secondAction:(SEL)secondAction
{
UIView *view = [[UIViewalloc]initWithFrame:CGRectMake(0,0,80,44)];
view.backgroundColor = [UIColorclearColor];
UIButton *firstButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
firstButton.frame = CGRectMake(40, 0, 40, 44);
[firstButton setImage:firstImageforState:UIControlStateNormal];
[firstButton addTarget:selfaction:firstActionforControlEvents:UIControlEventTouchUpInside];
firstButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentRight;
[firstButton setImageEdgeInsets:UIEdgeInsetsMake(0,0,0,5 *kScreenWidth/375.0)];
[view addSubview:firstButton];
UIButton *secondButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
secondButton.frame = CGRectMake(0, 0, 40, 44);
[secondButton setImage:secondImageforState:UIControlStateNormal];
[secondButton addTarget:selfaction:secondActionforControlEvents:UIControlEventTouchUpInside];
secondButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentRight;
[secondButton setImageEdgeInsets:UIEdgeInsetsMake(0,0,0,0 *kScreenWidth/375.0)];
[view addSubview:secondButton];
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItemalloc]initWithCustomView:view];
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
}
- (void)addRightThreeBarButtonsWithFirstImage:(UIImage *)firstImage firstAction:(SEL)firstAction secondImage:(UIImage *)secondImage secondAction:(SEL)secondAction thirdImage:(UIImage *)thirdImage thirdAction:(SEL)thirdAction
{
UIView *view = [[UIViewalloc]initWithFrame:CGRectMake(0,0,120,44)];
view.backgroundColor = [UIColorclearColor];
UIButton *firstButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
firstButton.frame = CGRectMake(80, 0, 40, 44);
[firstButton setImage:firstImageforState:UIControlStateNormal];
[firstButton addTarget:selfaction:firstActionforControlEvents:UIControlEventTouchUpInside];
firstButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentRight;
[firstButton setImageEdgeInsets:UIEdgeInsetsMake(0,0,0,5 *kScreenWidth/375.0)];
[view addSubview:firstButton];
UIButton *secondButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
secondButton.frame = CGRectMake(44, 0, 40, 44);
[secondButton setImage:secondImageforState:UIControlStateNormal];
[secondButton addTarget:selfaction:secondActionforControlEvents:UIControlEventTouchUpInside];
secondButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentRight;
[secondButton setImageEdgeInsets:UIEdgeInsetsMake(0,0,0,8 *kScreenWidth/375.0)];
[view addSubview:secondButton];
UIButton *thirdButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
thirdButton.frame = CGRectMake(0, 0, 40, 44);
[thirdButton setImage:thirdImageforState:UIControlStateNormal];
[thirdButton addTarget:selfaction:thirdActionforControlEvents:UIControlEventTouchUpInside];
[view addSubview:thirdButton];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItemalloc]initWithCustomView:view];
}
如果你的需求是三个四个item按钮,可以仿照上边两个item按钮的方法,自行处理。
有问题请留言,我看到后会及时处理。
注意:以上我写的方法,已经不会偏移了。
但是会出现点击不到item情况。借鉴了UINavigation-SXFixSpace的几个分类,解决了我的问题。谢谢此位大哥的分享。
点击下载demo
- iOS11NavigationItem偏移,iOS11适配问题,iOS11导航栏返回偏移,iOS11BarButtonItem偏移,Xcode9遇见的问题
- iOS11导航栏自定义按钮偏移问题
- iOS11导航栏自定义按钮偏移问题
- iOS11 UIScrollView 偏移量问题
- iOS11项目适配 UIScorllView下移和导航栏返回按钮偏移
- iOS11 完美解决导航栏按钮偏移问题 韩俊强的博客
- iOS11 tableView内容向下偏移20pt或向下偏移64pt的问题?
- IOS 之iIOS11更新 导航返回按钮偏移的问题。。。。。
- IOS 11导航返回按钮偏移的问题
- iOS 11 导航栏按钮偏移问题
- 偏移量的问题
- 自定义返回按钮偏移问题
- IOS7适配之:返回按钮偏移问题
- iOS 导航栏属性 透明属性translucent 偏移64 滑动视图内容自动向下偏移的问题总结
- 关于偏移地址的问题
- 关于内存偏移的问题
- 一个指针偏移的问题
- SeeKBar 背景图片偏移的问题
- 解决Xcode9 Swift4下Cocoapods编译Swift第三方时报错
- <1> 可视化排序
- Coding life,云栖社区的个性化首页上线
- 好东西得仔细研究
- 关注商业细节的企业财务分析
- iOS11NavigationItem偏移,iOS11适配问题,iOS11导航栏返回偏移,iOS11BarButtonItem偏移,Xcode9遇见的问题
- iOS 开发 -- 使用KeyChain保存用户名、密码并实现自动登录
- impala介绍
- Java异常处理体系—Error类与Exception类的区别
- READ ME FIRST!!!
- caffe图像可视化(一)——featuremap可视化
- ViewPager无限轮播
- C++学习笔记---函数模板
- mui的省市区的三级联动改编 分级弹出选择