From 175862009ecc98a68a624db447d7f59d39f3b273 Mon Sep 17 00:00:00 2001 From: daniels_liu Date: Fri, 14 Aug 2020 18:22:45 +0800 Subject: [PATCH] change bounds to frame --- DNSPageView/PageContentView.swift | 15 ++++++++------- DNSPageView/PageTitleView.swift | 2 +- DNSPageView/PageView.swift | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/DNSPageView/PageContentView.swift b/DNSPageView/PageContentView.swift index faadf25..cd463bf 100644 --- a/DNSPageView/PageContentView.swift +++ b/DNSPageView/PageContentView.swift @@ -90,10 +90,10 @@ open class PageContentView: UIView { override open func layoutSubviews() { super.layoutSubviews() - collectionView.frame = bounds + collectionView.frame = CGRect(origin: CGPoint.zero, size: frame.size) let layout = collectionView.collectionViewLayout as! PageCollectionViewFlowLayout - layout.itemSize = bounds.size - layout.offset = CGFloat(currentIndex) * bounds.size.width + layout.itemSize = frame.size + layout.offset = CGFloat(currentIndex) * frame.size.width } } @@ -123,7 +123,8 @@ extension PageContentView: UICollectionViewDataSource { let childViewController = childViewControllers[indexPath.item] eventHandler = childViewController as? PageEventHandleable - childViewController.view.frame = cell.contentView.bounds + childViewController.view.frame = CGRect(origin: CGPoint.zero, size: cell.contentView.frame.size) + cell.contentView.addSubview(childViewController.view) return cell @@ -158,7 +159,7 @@ extension PageContentView: UICollectionViewDelegate { private func collectionViewDidEndScroll(_ scrollView: UIScrollView) { - let index = Int(round(scrollView.contentOffset.x / scrollView.bounds.width)) + let index = Int(round(scrollView.contentOffset.x / scrollView.frame.width)) delegate?.contentView(self, didEndScrollAt: index) @@ -187,12 +188,12 @@ extension PageContentView: UICollectionViewDelegate { var sourceIndex = 0 - progress = scrollView.contentOffset.x.truncatingRemainder(dividingBy: scrollView.bounds.width) / scrollView.bounds.width + progress = scrollView.contentOffset.x.truncatingRemainder(dividingBy: scrollView.frame.width) / scrollView.frame.width if progress == 0 || progress.isNaN { return } - let index = Int(scrollView.contentOffset.x / scrollView.bounds.width) + let index = Int(scrollView.contentOffset.x / scrollView.frame.width) if collectionView.contentOffset.x > startOffsetX { // 左滑动 sourceIndex = index diff --git a/DNSPageView/PageTitleView.swift b/DNSPageView/PageTitleView.swift index 3bc6234..6da9951 100644 --- a/DNSPageView/PageTitleView.swift +++ b/DNSPageView/PageTitleView.swift @@ -125,7 +125,7 @@ open class PageTitleView: UIView { override open func layoutSubviews() { super.layoutSubviews() - scrollView.frame = self.bounds + scrollView.frame = CGRect(origin: CGPoint.zero, size: frame.size) setupLabelsLayout() setupBottomLineLayout() diff --git a/DNSPageView/PageView.swift b/DNSPageView/PageView.swift index 1a63ab3..cd6cd31 100644 --- a/DNSPageView/PageView.swift +++ b/DNSPageView/PageView.swift @@ -59,11 +59,11 @@ open class PageView: UIView { extension PageView { private func setupUI() { - let titleFrame = CGRect(x: 0, y: 0, width: bounds.width, height: style.titleViewHeight) + let titleFrame = CGRect(x: 0, y: 0, width: frame.width, height: style.titleViewHeight) titleView.frame = titleFrame addSubview(titleView) - let contentFrame = CGRect(x: 0, y: style.titleViewHeight, width: bounds.width, height: bounds.height - style.titleViewHeight) + let contentFrame = CGRect(x: 0, y: style.titleViewHeight, width: frame.width, height: frame.height - style.titleViewHeight) contentView.frame = contentFrame addSubview(contentView)