如何表示弃用的API
+ (void)showWithMaskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use show and setDefaultMaskType: instead.")));
使用
__attribute__
,deprecated
关键字表示已过时的API
单例创建方式
static dispatch_once_t once;
static SVProgressHUD *sharedView;
dispatch_once(&once, ^{
sharedView = [[self alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
});
return sharedView;
使用GCD的
dispatch_once
函数
数组元素的倒序遍历
NSEnumerator *frontToBackWindows = [UIApplication.sharedApplication.windows reverseObjectEnumerator];
for (UIWindow *window in frontToBackWindows){
BOOL windowOnMainScreen = window.screen == UIScreen.mainScreen; // 为设备屏幕
BOOL windowIsVisible = !window.hidden && window.alpha > 0;
BOOL windowLevelNormal = window.windowLevel == UIWindowLevelNormal;
if(windowOnMainScreen && windowIsVisible && windowLevelNormal){
[window addSubview:self.overlayView];
break;
}
}
枚举器,反向遍历
reverseObjectEnumerator
;
objectEnumerator
为正向遍历,返回NSEnumerator<Object>
对象,Object
表示真正的对象类型.
if-else条件编译宏的使用
#if conditionA
// ...
#elif conditionB
// ...
#else
// ...
#endif
将浮点数取值的C
函数
ceilf(5.3) // 6
floorf(5.6) // 5
ceil表示向上取整;floorf表示向下取整
Accessibility 支持
self.accessibilityIdentifier = @"SVProgressHUD";
self.accessibilityLabel = @"SVProgressHUD";
self.isAccessibilityElement = YES;
让控件或者对象自定义的唯一可识别的标签,并且关联
user interface
计算文字的尺寸
stringRect = [string boundingRectWithSize:constraintSize
options:(NSStringDrawingOptions)(NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin)
attributes:@{NSFontAttributeName: self.stringLabel.font}
context:NULL];
首先需要大致限制尺寸,和
NSStringDrawingOptions
表示了绘制的文字在计算高度和宽度时所参考的起始点和结束点,涉及到印刷字体的排版相关知识
动画事务的使用
[CATransaction begin];
[CATransaction setDisableActions:YES];
[_hudView.layer removeAllAnimations];
// ....
[CATransaction commit];
CATransaction
使用begin
开始,并对应commit
结束;setDisableActions:YES
用于当此transaction
内动画属性变化需要中断此次事务
网友评论