忽略警告
忽略可能存在内存泄漏警告
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[moduleInstance performSelector:selector
withObject:[UPContext sharedInstance]];
#pragma clang diagnostic pop
}
支持http协议
ios9开始苹果安全会自动先知http网址的访问,如果想开放此访问,需要在info.plist
中进行修改。
添加App Transport Security Setting
,其中继续添加Allow Arbitrary Loads
,设置为Yes
。
宏定义中"##","@#"
例如DKNightVersionManager
中宏定义语法
#define DKColorPickerWithKey(key) [[DKColorTable sharedColorTable] pickerWithKey:@#key]
使用时:
self.dk_backgroundColorPicker = DKColorPickerWithKey(backgroundColor);
backgroundColor
本身不是字符串,可在宏定义中经过@#
字符,其中#
为字符串化的意思,转换为@"backgroundColor"
字符串。
此为C
中语法。
可参考如下:
#define f(a,b) a##b //##被称为连接符(concatenation),把宏参数与之前的token(参数/字符串空格等)连接起来。
#define g(a) #a //#:把宏参数转换为字符串。不管该参数宏什么,即“原貌”用字符串显示出来
音频后台播放
// Apps using this category don't mute when the phone's mute button is turned on, but play sound when the phone is silent
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
渐变色
CAGradientLayer *graLayer = [CAGradientLayer layer];
graLayer.frame = CGRectMake(100, 100, 200, 200);
graLayer.colors = @[
(__bridge id)[UIColor redColor].CGColor,
(__bridge id)[UIColor yellowColor].CGColor
];
// graLayer.locations = @[@0, @0.2];
graLayer.startPoint = CGPointMake(0, 0);
graLayer.endPoint = CGPointMake(1, 1);
[self.view.layer addSublayer:graLayer];
旋转适配
- (void)viewSafeAreaInsetsDidChange{
[super viewSafeAreaInsetsDidChange];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
if (@available(iOS 11.0, *)){
if (deviceOrientationisLandscape()) {
[self.commentMoreBtn mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.view.mas_safeAreaLayoutGuideRight).offset(-15);
}];
}else
{
[self.commentMoreBtn mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-15);
}];
}
}
#endif
}
系统下拉手势冲突问题
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {
return UIRectEdgeAll;
}