iOS 开发技巧总结

1. 添加定时器的常用代码

 - (void)delayEnableTabButton
{
self.tabChannelButton.enabled = NO;
[self appendTimer];
} - (void)appendTimer
{
if (_resumeTimer == nil)
{
_resumeTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(enableTabChannelButton) userInfo:nil repeats:NO];
}
} - (void)enableTabChannelButton
{
self.tabChannelButton.enabled = YES;
[self removeTimer];
} - (void)removeTimer
{
if (_resumeTimer != nil)
{
[_resumeTimer invalidate];
_resumeTimer = nil;
}
} - (void)dealloc
{
[self removeTimer];
}

2. 对于用户多次点击的事件,为防止重复调用而覆盖操作,可以延迟执行.如:

     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (!_processFlowView.hidden) {
return ;
}
_processFlowView.hidden = NO;
_processFlowViewLeft.constant = _windNameStart;
[self layoutIfNeeded];
[UIView animateWithDuration:0.5 animations:^{
_processFlowViewLeft.constant = _windNameEnd;
[self layoutIfNeeded];
} completion:^(BOOL finished) {
_processFlowView.hidden = YES;
}];
});

3. 写  UI 的代码时, 能复制粘贴的尽量复制粘贴, 快速开发...可以使用 headerTitleLabel1, headerTitleLabel2, middleTitleLabel1来代替复杂的命名规则.

4. 对于 UI 比较复杂的界面, 可以定义多个大容器, 对于修改 UI 的话, 比较方便.

5. 写  UI 的时候, 可以打开 xcode 的分屏功能, 左右两个界面对照编辑

6. 对于数据的特殊显示, 如进度为100%时, 仍显示99%, 可以在代码的最底层处理, 也就是 UI层, 在设置 UIlabel 的 text 时做处理, 其他地方就不用重复处理了, 以免出问题了不好查找.

上一篇:转载:AbstractQueuedSynchronizer的介绍和原理分析


下一篇:题解 P1944 最长括号匹配_NOI导刊2009提高(1)