Skip to content

Commit

Permalink
change bounds to frame
Browse files Browse the repository at this point in the history
  • Loading branch information
daniels_liu committed Aug 14, 2020
1 parent 2582801 commit 1758620
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions DNSPageView/PageContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion DNSPageView/PageTitleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions DNSPageView/PageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 1758620

Please sign in to comment.