iOS14 适配

1、iPhone尺寸。
2、关于IDFA获取权限。
3、UITableViewCell 兼容问题。
4、UIPageControl的兼容问题。
5、相机和麦克风、黏贴板、定位、Local Network、Wifi-Address…

一、iPhone尺寸
iPhone最新尺寸.png
二、关于IDFA获取权限
 if (@available(iOS 14, *)) {
    [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
        if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
            self.idfa = [[ASIdentifierManager sharedManager] advertisingIdentifier].UUIDString;
        }
    }];
  } else {
    // 使用原方式访问 IDFA
    if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
        self.idfa = [[ASIdentifierManager sharedManager] advertisingIdentifier].UUIDString;
    }
  }
三、UITableViewCell 兼容问题
解决方案:之前[self addSubview:cell]  改为[self.contentView addSubview:cell]
原因:因为self的视图被self.contentView遮盖,影响的view的点击交互
四、UIPageControl的兼容问题
 [_pageControl setValue:[UIImage imageNamed:@"app_lanuch_page_no"] forKeyPath:@"pageImage"];
 [_pageControl setValue:[UIImage imageNamed:@"app_lanuch_page_selected"] forKeyPath:@"currentPageImage"];
以上问题出现崩溃,需要自己绘制显示的选中的pageControl和未选中的pageControl的样式。
参考CJWPageControl的方法:

效果:
截屏2020-10-20 下午8.01.36.png

代码:

CJWPageControl.h
#import 
NS_ASSUME_NONNULL_BEGIN
@interface CJWPageControl : UIView
@property (nonatomic, assign) NSInteger currentPageNumber;
@property (nonatomic, assign) NSInteger pageCount;
@property (nonatomic, assign) NSInteger padding;
@property (nonatomic, strong) UIView *unselectedView;
@property (nonatomic, strong) UIView *selectedView;
@end
NS_ASSUME_NONNULL_END

CJWPageControl.m
#import "CJWPageControl.h"
@interface CJWPageControl()
@property (nonatomic, strong) NSMutableArray *numberSubviews;   // 所有
@end
@implementation CJWPageControl
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.numberSubviews = [[NSMutableArray alloc] init];
    }
    return self;
}
- (void)setFrame:(CGRect)frame {
    [super setFrame:frame];
    [self reSetPageControl];
}
- (void)reSetPageControl {
  CGFloat x = 0;
    for (int i = 0; i < self.pageCount; i++) {
        UIView *view = [_numberSubviews objectAtIndex:i];
        if (_currentPageNumber == i) {
            [self changeViewLayerFromView:self.selectedView toView:view];
        } else {
            [self changeViewLayerFromView:self.unselectedView toView:view];
        }
        view.frame = CGRectMake(x, 0, view.frame.size.width, view.frame.size.height);
        x += (view.frame.size.width + _padding);
    }
}
- (void)setCurrentPageNumber:(NSInteger)currentPageNumber {
    _currentPageNumber = currentPageNumber;
    if (_currentPageNumber < _numberSubviews.count) {
        [self reSetPageControl];
    }
}
- (void)setPageCount:(NSInteger)pageCount {
    _pageCount = pageCount;
    [self clearSubviews];
    for (int i = 0; i < pageCount; i++) {
        UIView *view = [[UIView alloc] initWithFrame:self.unselectedView.frame];
        view.clipsToBounds = YES;
        [self addSubview:view];
        [_numberSubviews addObject:view];
    }
}
- (void)changeViewLayerFromView:(UIView *)fromView toView:(UIView *)toView {
    toView.frame = fromView.frame;
    toView.layer.borderColor = fromView.layer.borderColor;
    toView.layer.borderWidth = fromView.layer.borderWidth;
    toView.backgroundColor = fromView.backgroundColor;
    toView.layer.cornerRadius = fromView.layer.cornerRadius;
}
- (void)clearSubviews {
    [_numberSubviews removeAllObjects];
    for (UIView *subView in self.subviews) {
        [subView removeFromSuperview];
   }
}
@end

调用:


截屏2020-10-20 下午8.06.08.png
五、相机和麦克风、黏贴板、定位、Local Network、Wifi-Address…

参考文章:https://juejin.im/post/6850418120923250701

你可能感兴趣的:(iOS14 适配)