一. 前言

平时在处理问题的时候,经常会遇到一些奇奇怪怪的问题,今天在这里将其记录下来。这里将会列举几个常用的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];
}
}

实战荟萃-UI篇的更多相关文章

  1. iOS进阶指南试读之UI篇

    iOS进阶指南试读之UI篇 UI篇 UI是一个iOS开发工程师的基本功.怎么说?UI本质上就是你调用苹果提供给你的API来完成设计师的设计.所以,想提升UI的功力也很简单,没事就看看UIKit里的各个 ...

  2. iOS开发UI篇—CAlayer(自定义layer)

    iOS开发UI篇—CAlayer(自定义layer) 一.第一种方式 1.简单说明 以前想要在view中画东西,需要自定义view,创建一个类与之关联,让这个类继承自UIView,然后重写它的Draw ...

  3. iOS开发UI篇—UITabBarController简单介绍

    iOS开发UI篇—UITabBarController简单介绍 一.简单介绍 UITabBarController和UINavigationController类似,UITabBarControlle ...

  4. iOS开发UI篇—懒加载

    iOS开发UI篇—懒加载 1.懒加载基本 懒加载——也称为延迟加载,即在需要的时候才加载(效率低,占用内存小).所谓懒加载,写的是其get方法. 注意:如果是懒加载的话则一定要注意先判断是否已经有了, ...

  5. iOS开发UI篇—CAlayer层的属性

    iOS开发UI篇—CAlayer层的属性 一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property ...

  6. iOS开发UI篇—CAlayer(创建图层)

    iOS开发UI篇—CAlayer(创建图层) 一.添加一个图层 添加图层的步骤: 1.创建layer 2.设置layer的属性(设置了颜色,bounds才能显示出来) 3.将layer添加到界面上(控 ...

  7. iOS开发UI篇—CALayer简介

    iOS开发UI篇—CALayer简介   一.简单介绍 在iOS中,你能看得见摸得着的东西基本上都是UIView,比如一个按钮.一个文本标签.一个文本输入框.一个图标等等,这些都是UIView. 其实 ...

  8. iOS开发UI篇—核心动画(UIView封装动画)

    iOS开发UI篇—核心动画(UIView封装动画) 一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画 ...

  9. iOS开发UI篇—核心动画(转场动画和组动画)

    转自:http://www.cnblogs.com/wendingding/p/3801454.html iOS开发UI篇—核心动画(转场动画和组动画) 一.转场动画简单介绍 CAAnimation的 ...

随机推荐

  1. WCF服务属性注入基础设施

    WCF服务属性注入基础设施 WCF的服务的创建行为:使用默认构造函数创建WCF服务对象.如果我们想要在WCF内使用外部对象,最简单的方式就是把外部对象做成全局对象.然而这样的话会增加全局对象的数量,让 ...

  2. Java Concurrency (1)

    Memory that can be shared betweenthreads is called shared memory or heap memory. The term variable a ...

  3. spring mvc页面显示图片失败

    在配置文件中需要映射静态资源 <!-- 当在web.xml 中 DispatcherServlet使用 <url-pattern>/</url-pattern> 映射时, ...

  4. 在收购Sun六年后,Oracle终于瞄准了Java的非付费用户

    Java语言毫无疑问已经成为软件社区的一个品牌和开放的产业标准.自从2010年Oracle收购了Sun Microsystems公司之后,很多人就担心这在某种程度上是软件开源产业的一次失败,甚至会造成 ...

  5. dapper 可空bool转换出错及解决方案

    最近使用entityframewok生成数据库,使用dapper来访问数据库,产生了一个意外的bug,下面是产生bug的示例以及解决方案. 由于用entityframework生成数据库,默认情况en ...

  6. windows下npm scripts不能执行的问题

    最近在学webpack为了方便把运行脚本写入package.json文件中,如下: "scripts": { "start": "webpack-de ...

  7. margin塌陷现象(即在内层设置margin-top无效的解决办法)

    有两个有嵌套关系的div,如果外层div的父元素的padding值为0,那么内层子div的margin-top或margin-bottom的值会转移给外层的父div,即magrin塌陷现象. 解决办法 ...

  8. Nexpose

    下载: https://www.rapid7.com/products/nexpose/nexpose-enterprise-trial-thank-you.jsp注册: https://www.ra ...

  9. hadoop端口配置指南

    获取默认配置 配置hadoop,主要是配置core-site.xml,hdfs-site.xml,mapred-site.xml三个配置文件,默认下来,这些配置文件都是空的,所以很难知道这些配置文件有 ...

  10. Python 的基本使用说明

    1.先定义一个被调用的模块,文件名 cnf.py #!/usr/bin/ #coding=utf- import sys reload(sys) sys.setdefaultencoding( &qu ...