1候醒、蘋果對導(dǎo)航欄的性能做了優(yōu)化,默認(rèn)情況下次慢,如果導(dǎo)航欄與視圖沒有折疊,導(dǎo)航欄的背景透明翔曲,如果系統(tǒng)檢測到有重疊的話迫像,會變成毛玻璃的效果
if (@available(iOS 15.0, *)) {
NSDictionary *textAttr = @{
NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName: [UIFont systemFontOfSize:17],
};
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
[appearance setShadowImage:[[UIImage alloc] init]];
appearance.titleTextAttributes = textAttr;
[appearance setBackgroundColor:TAD_THM.navigationBackgroundColor];
// 隱藏分割線 設(shè)置一個(gè)透明或者純色的圖片 設(shè)置nil 或者 [UIImage new]無效
[appearance setBackgroundImage:[UIImage zt_imageWithPureColor:[UIColor whiteColor]]];
[appearance setShadowImage:[UIImage zt_imageWithPureColor:[UIColor whiteColor]]];
[[UINavigationBar appearance] setScrollEdgeAppearance: appearance];
// 滾動頁面 防止導(dǎo)航欄會變白色
[[UINavigationBar appearance] setStandardAppearance:appearance];
[[UINavigationBar appearance] setCompactAppearance:appearance];
// 隱藏導(dǎo)航欄底部一個(gè)線條
[self.navigationController.navigationBar.subviews.firstObject.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:NSClassFromString(@"_UIBarBackgroundShadowContentImageView")] || [obj isKindOfClass:NSClassFromString(@"_UIBarBackgroundShadowView")]) {
obj.hidden=YES;
}
}];
}
顏色轉(zhuǎn)圖片
+ (UIImage *)zt_imageWithPureColor:(UIColor *)color {
UIGraphicsBeginImageContextWithOptions(CGSizeMake(3, 3), NO, [UIScreen mainScreen].scale);
UIBezierPath* p = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 3, 3)];
[color setFill];
[p fill];
UIImage* img = UIGraphicsGetImageFromCurrentImageContext();
return img;
}
+ (UIImage *)zt_imageWithPureColor:(UIColor *)color size:(CGSize )size{
UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
UIBezierPath* p = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, size.width, size.height)];
[color setFill];
[p fill];
UIImage* img = UIGraphicsGetImageFromCurrentImageContext();
return img;
}
UINavigationBar默認(rèn)是透明的,有滑動時(shí)會逐漸變?yōu)槟:Ч椋梢酝ㄟ^改變scrollEdgeAppearance屬性直接變?yōu)槟:Ч?/p>
if (@available(iOS 15.0, *)){
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
appearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
navBar.scrollEdgeAppearance = appearance;
}
2闻妓、UITableView新增了一條新屬性:sectionHeaderTopPadding, 默認(rèn)會給每一個(gè)section header 增加一個(gè)高度掠械,當(dāng)我們使用 UITableViewStylePlain 初始化UITableView的時(shí)候由缆,能發(fā)現(xiàn)sectionHeader增高了22px。解決辦法就是手動去除這個(gè)高度
if (@available(iOS 15.0, *)) {
table.sectionHeaderTopPadding = 0;
}
全局適配設(shè)置
if (@available(iOS 15.0, *)) {
//設(shè)置默認(rèn)的分組頭部間隙為0
[UITableView appearance].sectionHeaderTopPadding = CGFLOAT_MIN;
}
3猾蒂、UIImageWriteToSavedPhotosAlbum存儲圖片之后的回調(diào)不再返回圖片了均唉,會返回nil,如果在回調(diào)方法里面操作image有可能會直接Crash肚菠,目前的解決辦法聲明一個(gè)全局image去記錄舔箭,后面再去操作
self.image = image;
UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:didFinishSavingWithError:contextInfo:), NULL);
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
// self.image doing...
}