一 Xcode12编译报错:
error: can't exec 'copypng' (No such file or directory) Command copypng failed with exit code 71
;在Xcode12中编译时有这个报错,因项目需求,以前的Xcode11还要保留,再加上mac空间小,安装的时候删除了一些文件,借助SD解压,然后在复制到mac的应用程序中,就报错了, 所以重新安装;详见:https://stackoverflow.com/questions/40998809/command-copypng-failed-with-exit-code-71
二 UIPageControl自定义适配
if (@available(iOS 14.0,*)) {
// 先去遍历试图
if (![self findIndicatorContentView]) {
for (int i = 0; i < self.numberOfPages; i++) {
// 图片无法正确显示 有bug
if (i == self.currentPage) {
[self setIndicatorImage:[self.inactiveImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forPage:self.currentPage];
}else{
[self setIndicatorImage:[self.activeImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forPage:i];
}
//
}
}
// 自定义样式
int temp = 0;
for ( id view in [self findIndicatorContentView].subviews) {
if ([view isKindOfClass:[UIImageView class]]) {
if (self.currentTintColor) {
self.currentPageIndicatorTintColor = self.currentTintColor;
//self.currentPageIndicatorTintColor = [UIColor orangeColor];
}
if (self.inactiveTintColor) {
self.pageIndicatorTintColor = self.inactiveTintColor;
//self.pageIndicatorTintColor = [UIColor grayColor];
}
UIImageView * imageView = (UIImageView *)view;
//imageView.contentMode = UIViewContentModeCenter;
if (temp == self.currentPage) {
imageView.image = [self.inactiveImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}else{
imageView.image = [self.activeImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
}
temp++;
}
}
-(UIView *)findIndicatorContentView{
Class contentViewClass = NSClassFromString(@"_UIPageControlContentView");
Class indicatorContentViewClass = NSClassFromString(@"_UIPageControlIndicatorContentView");
for (UIView *contentView in self.subviews) {
if ([contentView isKindOfClass:contentViewClass]) {
for (UIView *indicatorContentView in contentView.subviews) {
if ([indicatorContentView isKindOfClass:indicatorContentViewClass]) {
return indicatorContentView;
}
}
}
}
return nil;
}
参考https://www.cnblogs.com/4zjq/archive/2020/11/25/14034333.html
三 UITableViewController 在iOS14上,打印self.view为
; layer = ; contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 0, 0}; dataSource: <_UIFilteredDataSource: 0x280789080>>
self.view.frame.size.width == 0 大坑啊!!!
四 Widget的适配
3.1 在iOS14上,推出了WidgetKit框架,还没有用到,但要沿用以前的Today Extension ,界面变形,需要适配.
-(UIView *)noneDataView{
if (!_noneDataView) {
_noneDataView = [[UIView alloc] initWithFrame:CGRectZero];
if (@available(iOS 14.0 , *)) {
_noneDataView.frame = CGRectMake(0, 0,ScreenWidth - 40,widgetHeigth );
}else{
_noneDataView.frame = CGRectMake(0, 0,widgetWidth,widgetHeigth );
}
}
return _noneDataView;
}
3.2 学习WidgetKit
(1) 在学习WidgetKit之前,需要先调研SwiftUI
参考一些优质博文:
https://gitee.com/TheAlgorithms/SwiftUI?utm_source=alading&utm_campaign=repo#Text_D
http://www.zyiz.net/tech/detail-141529.html
(2) supportedFamilies:
默认情况下只有一个widget WidgetConfiguration
支持3种尺寸 supportedFamilies 赋值4个卡片 也展示3个 ,可以设置2个卡片,默认打开第一个卡片.展示为小,中,大.
.supportedFamilies([.systemSmall,.systemMedium,.systemLarge]
.supportedFamilies([.systemMedium,.systemSmall,.systemLarge]
(3) 自定义多个widget
@main
/// 自定义widget 多个
struct HunterWidgets:WidgetBundle {
@WidgetBundleBuilder
var body: some Widget{
PoetryWidget1();
PoetryWidget2();
PoetryWidget3();
}
// 小
struct PoetryWidget1: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(kind: "TestWidgetIOS14_1", provider: PoetryProvider()) { entry in
PoetryWidgetView(entry: entry)
}
.configurationDisplayName("你的世界真好")
.description("描述美妙不可言传")
.supportedFamilies([.systemSmall])
}
}
//中
struct PoetryWidget2: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(kind: "TestWidgetIOS14_2", provider: PoetryProvider()) { entry in
PoetryWidgetView(entry: entry)
}
.configurationDisplayName("每日一湿")
.description("优文章")
.supportedFamilies([.systemMedium])
}
}
// 小
struct PoetryWidget3: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(kind: "TestWidgetIOS14_3", provider: PoetryProvider()) { entry in
PoetryWidgetView(entry: entry)
}
.configurationDisplayName("每日三湿")
.description("我的文章")
.supportedFamilies([.systemSmall])
}
}
(4) list组件无法再WidgetKit上使用
4 objc_msgSender()报错
objc_msgSend(self, @selector(setName:),str);
改成((id (*)(Class _Nullable, SEL _Nonnull, NSString *)) (void *) objc_msgSend)(self, @selector(setName:),str)
objc_msgSend(observer, @selector(observeValueForKeyPath:ofObject:change:context:),@"name",self,@{@"new":str},nil);
改成 ((id (*)(id _Nullable,SEL _Nonnull ,NSString *, Class _Nullable,NSDictionary*,NSNull*)) (void *) objc_msgSend)(observer, @selector(observeValueForKeyPath:ofObject:change:context:),@"name",self,@{@"new":str},nil);