ios 开发小记 (四)

开发中的常见的问题:

1、NSDictionary

keyEnumerator 用来遍历dict

但是在dict为空的时候调用会报错 

使用前要注意。

 

2、URL Scheme
简单来叙述:
URL Scheme就是一个应用的网址,当访问到应用对应的网址的时候,会打开应用。
APP_A 打开 APP_B 的流程:
1,APP_B 自定义URL scheme;
2,安装并运行APP_B;(相当于注册)
3,APP_A通过
 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
打开APP_B;(可以传递参数) 
 
 
 
3、Storyboard
1. Storyboard中的First Responder只是一个placeholder,它不是具体指向哪个responder,
 
2. 如果程序不在乎谁是First Responder,都让First Responder执行某个action(比如这里的paste:),那么我们就可以把event发给First Responder。 
 
 
 4、Autoresize
autoresize的具体内容:
typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
    UIViewAutoresizingNone                 = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};

UIViewAutoresizingNone就是不自动调整。
UIViewAutoresizingFlexibleLeftMargin 自动调整与superView左边的距离,保证与superView右边的距离不变。
UIViewAutoresizingFlexibleRightMargin 自动调整与superView的右边距离,保证与superView左边的距离不变。
UIViewAutoresizingFlexibleTopMargin 自动调整与superView顶部的距离,保证与superView底部的距离不变。
UIViewAutoresizingFlexibleBottomMargin 自动调整与superView底部的距离,也就是说,与superView顶部的距离不变。
UIViewAutoresizingFlexibleWidth 自动调整自己的宽度,保证与superView左边和右边的距离不变。
UIViewAutoresizingFlexibleHeight 自动调整自己的高度,保证与superView顶部和底部的距离不变。
UIViewAutoresizingFlexibleLeftMargin  |UIViewAutoresizingFlexibleRightMargin 自动调整与superView左边的距离,保证与左边的距离和右边的距离和原来距左边和右边的距离的比例不变。比如原来距离为20,30,调整后的距离应为68,102,即68/20=102/30。

其它的组合类似。 

默认情况下,View的autoresizing工作会根据当前位置自动设置约束。我们在使用代码写自己的约束布局代码时,必须设置当前View的translatesAutoresizingMaskIntoConstraints为NO,否则无法正常运作。IB默认是NO。
这一点很重要!
 

 5、UIScrollView
scrollView 里面的元素所用的约束是与contentSize 所约束
 如果需要定长宽 需要与外界的的交互
 
 
 
 6、UIGestureRecognizer
UITapGestureRecognizer 与 view 一一对应
当把tap 加到第二个view,第一个view失效。
 
UIImageView  默认,是不让监听手势的,如果需要点击图片,记得在ib(attribute editor)中,打开。
 
 
7、NSNotification
Nsnotification 在发送的时候,要确保之前 监听的对象,仍有效
为了防止给失效的object 发送消息。
 
 
8、NSArray
for in  arr 中,不要对arr操作。 会爆炸。
 
 

posted on 2015-10-10 17:51  loying  阅读(174)  评论(1编辑  收藏  举报

导航