UIView拾遗

2017-04-28  本文已影响0人  事件_666

1 clipsToBounds 当subView超出自己的边框时是否剪裁。

Simulator Screen Shot 2017年4月28日 上午11.02.39.png
2 bounds 面试时被虐了平时没注意
每个人都会说bounds是对本坐标系的位置,但是不知道当改变with和height时是会以view的center为中心向外扩大。
例如说
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];
[view1 setBounds:CGRectMake(-20, -20, 200, 200)];
[view1 setBackgroundColor:[UIColor redColor]];
[self.view addSubview:view1];
view的frame为 {-40, -40}, {200, 200} 100分成两半一半50 减去原来的10 当然是-40了。
3 -(instancetype)initWithCoder:(NSCoder *)aDecoder
当view是从ib加载时调用这个方法,在这里自定义view。
4 +(BOOL)requiresConstraintBasedLayout
告诉系统哥们我是用的自动布局,请执行- (void)updateConstraints 方法吧。
5 sizeThatFits:
6 - (void)layoutSubviews setNeedsLayout
](apple-reference-documentation://hcKxHs2z9R)
7 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
是否接收手势 用途做不规则手势的判断(例如判断点击是否在一个圆内) MIO5U.png

9 tintColor(iOS7后) 会把父View的tintColor 传递过来 ,巧用此方法换肤
当父viewtintcolor 改变时会触发 tintColorDidChange方法,apple公司也是用心良苦

16 布局相关--本来不屑一顾的方法竟然被虐了。
A)- (void)layoutSubviews 注意旋转屏幕不会触发此方法 亲测(以前记得调用此方法)
触发时机1)addSubView
2)setFrame
3) [m_cView setNeedsLayout]; [m_cView layoutIfNeeded];这两个哥们配合使用。
B) translatesAutoresizingMaskIntoConstraints 默认yes
17当一个View上有很多输入框时 调用此方法回收键盘 。

20 远程事件

22 - (void)doesNotRecognizeSelector:(SEL)aSelector
放弃一个方法
app强调抛出一个异常

If you override this method, you must call super
or raise an [NSInvalidArgumentException
] exception at the end of your implementation. In other words, this method must not return normally; it must always result in an exception being thrown.

23
1 - (IMP)methodForSelector:(SEL)aSelector

AClass *aClass = [[AClass alloc] init];
IMP imp = [aClass methodForSelector:@selector(test:age:)];
imp();//这里不要参数你懂的
2 + (IMP)instanceMethodForSelector:(SEL)aSelector
IMP imp2 = [AClass
instanceMethodForSelector:@selector(test:age:)];
imp2()
24
1 禁止copy

251 一次被面试官问到这个方法是干什么的(日了狗了当时懵逼了),很简单历史遗留。_NSZone不在使用。

上一篇 下一篇

猜你喜欢

热点阅读