Open jianjianhao opened 4 years ago
问题解决:
SDCycleScrollView.m中
全局搜
self.pageControl.frame = CGRectMake(x, y, size.width, size.height);
替换为
if (@available(iOS 14.0, )) {
[self.pageControl mas_makeConstraints:^(MASConstraintMaker make) {
make.centerX.equalTo(self);
make.bottom.offset(-10);
make.height.offset(self.pageControlDotSize.height);
}];
}else{
self.pageControl.frame = CGRectMake(x, y, size.width, size.height);
}
问题解决: SDCycleScrollView.m中 全局搜 self.pageControl.frame = CGRectMake(x, y, size.width, size.height); 替换为 if ([self.pageControl isKindOfClass:[TAPageControl class]]) { CGRect pageControlFrame = CGRectMake(x, y, size.width, size.height); pageControlFrame.origin.y -= self.pageControlBottomOffset; pageControlFrame.origin.x -= self.pageControlRightOffset; self.pageControl.frame = pageControlFrame; }else{ if (_pageControlAliment == SDCycleScrollViewPageContolAlimentRight) { [self.pageControl mas_makeConstraints:^(MASConstraintMaker make) { if (@available(iOS 14.0, )) { make.right.equalTo(self).offset(25); }else{ make.right.equalTo(self).offset(-_pageControlRightOffset); } make.bottom.offset(-self.pageControlBottomOffset); make.height.offset(self.pageControlDotSize.height); }]; }else{ [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self); make.bottom.offset(-self.pageControlBottomOffset); make.height.offset(self.pageControlDotSize.height); }]; } }
嗯,我还是觉得自定义的可能会好点,毕竟也不知道iOS15会不会有坑了
谢谢大家分享,把iOS 14这个UIPageControl坑踩平了
找到 self.pageControl.frame = pageControlFrame; 修改为: if ([self.pageControl isKindOfClass:[TAPageControl class]]) { self.pageControl.frame = pageControlFrame; }else{
self.pageControl.translatesAutoresizingMaskIntoConstraints = NO;
[[self.pageControl.topAnchor constraintEqualToAnchor:self.topAnchor constant:pageControlFrame.origin.y] setActive:YES];
[[self.pageControl.heightAnchor constraintEqualToConstant:pageControlFrame.size.height] setActive:YES];
if (_pageControlAliment == SDCycleScrollViewPageContolAlimentRight) {
[[self.pageControl.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:-_pageControlRightOffset] setActive:YES];
} else {
[[self.pageControl.centerXAnchor constraintEqualToAnchor:self.centerXAnchor] setActive:YES];
}
}
再次找到:scrollViewDidScroll 在 UIPageControl pageControl = (UIPageControl )_pageControl; pageControl.currentPage = indexOnPageControl;
if (@available(iOS 14.0, *)) {
CGSize size = self.pageControlDotSize;
size.width = size.width - 2;
size.height = size.height - 2;
for (int i = 0; i < pageControl.numberOfPages; i++) {
// 颜色画图
UIImage *image = [UIImage createImageWithColor:self.pageDotColor size:size];
if (i == indexOnPageControl) {
image = [UIImage createImageWithColor:self.currentPageDotColor size:size];
}
// 图片 圆角
image = [image imageWithCornerRadius:size.height/2];
[pageControl setIndicatorImage:image forPage:i];
}
}
由于目前iOS14 UIPageControl系统api变动较大,导致PageControl点看不到,如果想使用iOS 14方案适配可以参考https://medium.com/彼得潘的-swift-ios-app-開發問題解答集/ios-14-進化的-page-control-f097af2801a6 个人是建议自定义UIControl解决可能会好点,可以参考框架里面的TAPageControl来弄,如果有更好的解决方法也可以分享一下 其实不知道苹果为啥每次更新系统都各种问题,要各种适配,坑的还是程序员,哎,真难!