实战荟萃-UI篇

一. 前言

平时在处理问题的时候,经常会遇到一些奇奇怪怪的问题,今天在这里将其记录下来。这里将会列举几个常用的UI问题进行讲解

二. 导航栏

iOS导航栏绝对是个巨坑。和很多朋友聊天都是自己实现了一套导航栏。当然,我个人是比较推崇用系统的方法。因为好处好几个:1.新特性推出之后简单易改 2.代码安装包体积的问题

1. 导航栏、状态栏的显示与隐藏

一般直接用系统的导航栏状态栏我们会这么做,优点:使用简单方便

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];

//恢复导航栏和状态栏
[self.navigationController setNavigationBarHidden:NO animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

//隐藏导航栏和状态栏
[self.navigationController setNavigationBarHidden:YES animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (BOOL)prefersStatusBarHidden
{
return YES;
}

2. 自定义导航栏

三. 键盘

UITableView上的键盘隐藏与弹起
以前碰到网上的代码实属坑,弹出的时候还有延时。凡事还是得自己动手试一试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-(void)registerNotifications
{
//注册通知
CZ_AddObj2DeftNotiCenter(self, @selector(keyboardWillShow:), UIKeyboardWillShowNotification, nil);
CZ_AddObj2DeftNotiCenter(self, @selector(keyboardWillHide:), UIKeyboardWillHideNotification, nil);
}
#pragma mark- TableView
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark- keyboard
- (void)keyboardWillShow:(NSNotification*)notification
{
NSDictionary* info = [notification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
// NSInteger curve = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
// NSTimeInterval duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

CGRect oldFram = self.cardDetailTableView.frame;
self.cardDetailTableView.frame = CGRectMake(oldFram.origin.x,- kbSize.height, oldFram.size.width, oldFram.size.height);


UIEdgeInsets contentInsets = UIEdgeInsetsMake(kbSize.height, 0.0, 0.0, 0.0);
self.cardDetailTableView.contentInset = contentInsets;
self.cardDetailTableView.scrollIndicatorInsets = contentInsets;

if(_tableRecognizer) {
[_cardDetailTableView removeGestureRecognizer:_tableRecognizer];
}
_tableRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
_tableRecognizer.numberOfTapsRequired = 1;
[_cardDetailTableView addGestureRecognizer:_tableRecognizer];
}


- (void)keyboardWillHide:(NSNotification *)notification
{
// NSDictionary* info = [notification userInfo];
CGRect oldFram = self.cardDetailTableView.frame;
self.cardDetailTableView.frame = CGRectMake(oldFram.origin.x, 0.0, oldFram.size.width, oldFram.size.height);
self.cardDetailTableView.contentInset = UIEdgeInsetsZero;
self.cardDetailTableView.scrollIndicatorInsets = UIEdgeInsetsZero;
}

- (void)hideKeyboard
{
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
if(_tableRecognizer) {
_tableRecognizer.delegate = nil;
[_cardDetailTableView removeGestureRecognizer:_tableRecognizer];
}
}
posted @   任淏  阅读(167)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2015-11-08 Objective-C对象模型及应用
点击右上角即可分享
微信分享提示