29.在一个自定义视图上有一个按钮视图该怎么实现
我以前的话把SEL当作参数来传,实在太low的实现方式了,应该整个把button当作参数来传!
inputToolBarView整个是一个自定义视图,上面有一个按钮
UIButton *sendButton = [self sendButton];
sendButton.enabled = NO;
sendButton.frame = CGRectMake(self.inputToolBarView.frame.size.width - 65.0f, 8.0f, 59.0f, 26.0f);
[sendButton addTarget:self
action:@selector(sendPressed:)
forControlEvents:UIControlEventTouchUpInside];
[self.inputToolBarView setSendButton:sendButton];
[self.view addSubview:self.inputToolBarView];
#pragma mark - Setters
- (void)setSendButton:(UIButton *)btn
{
if(sendButton)
[sendButton removeFromSuperview];
sendButton = btn;
[self addSubview:self.sendButton];
}
if(sendButton)
{ [sendButton removeFromSuperview]; }
这样的健壮性太强了!
30.踩坑!
有一处不是很懂的地方:radioScrollView的Frame/Bounds还没有开始设置,为什么提前的setFont拿bounds.size.height是有效果的?
//广播设置
_noticeLabel0 = [[UILabel alloc] initWithFrame:CGRectZero];
[_noticeLabel0 setFont:[UIFont systemFontOfSize:self.radioScrollView.bounds.size.height]];
NSLog(@"0_noticelabel0 's font is : %@", _noticeLabel0.font);
[_noticeLabel0 setTextColor:UIColorWithRGB(0x57, 0x57, 0x57)];
_noticeLabel0.backgroundColor = [UIColor clearColor];
_noticeLabel0.textColor = [UIColor lightGrayColor];
_noticeLabel0.userInteractionEnabled = NO;
[self.radioScrollView setContentSize:CGSizeZero];
[self.radioScrollView addSubview:_noticeLabel0];
在适当地方法输出:
后来把尺寸输出一检查代码,原来是原工程的人使用StoryBoard来做的,早就确定尺寸了。。。。。晕!
31. 替换资源的注意事项
替换资源之后最好的就是直接删掉整个然后重新导入。
32. nil NSNull区别使用的一个例子
是因为任何可动画的 layer 属性改变时,layer 都会寻找并运行合适的 'action' 来实行这个改变。在 Core Animation 的专业术语中就把这样的动画统称为动作 (action,或者 CAAction)。
layer 通过向它的 delegate 发送 actionForLayer:forKey: 消息来询问提供一个对应属性变化的 action。delegate 可以通过返回以下三者之一来进行响应:
它可以返回一个动作对象,这种情况下 layer 将使用这个动作。
它可以返回一个 nil, 这样 layer 就会到其他地方继续寻找。
它可以返回一个 NSNull 对象,告诉 layer 这里不需要执行一个动作,搜索也会就此停止。
参考:http://www.jianshu.com/p/079e5cf0f014