gsdios / SDCycleScrollView

Autoscroll Banner. 无限循环图片、文字轮播器。
MIT License
6.19k stars 1.51k forks source link

关于iOS14 UIPageControl 系统api变更导致看不到点问题 #632

Open jianjianhao opened 4 years ago

jianjianhao commented 4 years ago

由于目前iOS14 UIPageControl系统api变动较大,导致PageControl点看不到,如果想使用iOS 14方案适配可以参考https://medium.com/彼得潘的-swift-ios-app-開發問題解答集/ios-14-進化的-page-control-f097af2801a6 个人是建议自定义UIControl解决可能会好点,可以参考框架里面的TAPageControl来弄,如果有更好的解决方法也可以分享一下 其实不知道苹果为啥每次更新系统都各种问题,要各种适配,坑的还是程序员,哎,真难!

OyesOnoOmg commented 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); }

huangfangkai commented 4 years ago

问题解决: 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); }]; } }

jianjianhao commented 4 years ago

嗯,我还是觉得自定义的可能会好点,毕竟也不知道iOS15会不会有坑了

oymuzi commented 4 years ago

可以通过这个方式来解决 https://github.com/gsdios/SDCycleScrollView/issues/629#issuecomment-698150457

GentleForYou commented 4 years ago

谢谢大家分享,把iOS 14这个UIPageControl坑踩平了

emosiony commented 4 years ago

找到 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];
        }
    }