Fixed scaling issue on initial pull

This commit is contained in:
Peter Suwara
2019-05-14 15:36:14 +03:00
4 changed files with 25 additions and 40 deletions
@@ -54,8 +54,6 @@ final class TableCarouselView: UITableViewCell,
tableView.clipsToBounds = false
tableView.separatorInset.left = 0
//tableView.reloadData()
return tableView
}
@@ -73,7 +71,6 @@ final class TableCarouselView: UITableViewCell,
tableView.style(withDetail: .carousel)
tableView.clipsToBounds = false
//tableView.reloadData()
return tableView
} else {
let tableView = carouselItemTableView(atIndexPath: indexPath)
@@ -40,6 +40,7 @@ final class ViewController: UIViewController,
super.viewWillLayoutSubviews()
gradientView.layer.sublayers?[0].frame = gradientView.layer.bounds
applyImageScale(withScrollView: tableView)
}
private func styleViews() {
@@ -62,6 +63,25 @@ final class ViewController: UIViewController,
width: tableView.bounds.size.width,
height: tableView.bounds.size.height * 2)
}
private func applyImageScale(withScrollView scrollView: UIScrollView) {
whiteBottomView.frame = CGRect(origin: CGPoint(x: 0,
y: scrollView.contentSize.height - scrollView.contentOffset.y + 0),
size: whiteBottomView.frame.size)
let minScale:CGFloat = 1.1
let maxScale:CGFloat = 2.0
let offset = tableView.contentOffset.y
let height = tableView.contentSize.height
var scale = (1.0 / height) * offset
scale = scale * (maxScale - minScale)
scale += minScale
imageView.applyScale(scale)
}
// MARK: -
// MARK: UITableViewDataSource
@@ -148,20 +168,7 @@ final class ViewController: UIViewController,
// MARK: -
// MARK: UIScrollViewDelegate
func scrollViewDidScroll(_ scrollView: UIScrollView) {
whiteBottomView.frame = CGRect(origin: CGPoint(x: 0, y: scrollView.contentSize.height - scrollView.contentOffset.y + 0), size: whiteBottomView.frame.size)
let minScale:CGFloat = 1.1
let maxScale:CGFloat = 2.0
let offset = tableView.contentOffset.y
let height = tableView.contentSize.height
var scale = (1.0 / height) * offset
scale = scale * (maxScale - minScale)
scale += minScale
imageView.applyScale(scale)
applyImageScale(withScrollView: scrollView)
}
// MARK: -
@@ -7,7 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
1D0AA4C121E4AFFF00D5332F /* Circulararousel.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D0AA4BF21E4AFFF00D5332F /* Circulararousel.h */; settings = {ATTRIBUTES = (Public, ); }; };
1D0AA4C121E4AFFF00D5332F /* CircularCarousel.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D0AA4BF21E4AFFF00D5332F /* CircularCarousel.h */; settings = {ATTRIBUTES = (Public, ); }; };
1D0AA4CB21E4B06B00D5332F /* NSObjectExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D0AA4C721E4B06B00D5332F /* NSObjectExtension.swift */; };
1D0AA4CC21E4B06B00D5332F /* CircularCarouselDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D0AA4C821E4B06B00D5332F /* CircularCarouselDataSource.swift */; };
1D0AA4CD21E4B06B00D5332F /* CircularCarouselDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D0AA4C921E4B06B00D5332F /* CircularCarouselDelegate.swift */; };
@@ -21,7 +21,7 @@
/* Begin PBXFileReference section */
1D0AA4BC21E4AFFF00D5332F /* CircularCarousel.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CircularCarousel.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1D0AA4BF21E4AFFF00D5332F /* Circulararousel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Circulararousel.h; sourceTree = "<group>"; };
1D0AA4BF21E4AFFF00D5332F /* CircularCarousel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CircularCarousel.h; sourceTree = "<group>"; };
1D0AA4C021E4AFFF00D5332F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
1D0AA4C721E4B06B00D5332F /* NSObjectExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSObjectExtension.swift; sourceTree = "<group>"; };
1D0AA4C821E4B06B00D5332F /* CircularCarouselDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CircularCarouselDataSource.swift; sourceTree = "<group>"; };
@@ -68,7 +68,7 @@
1D0AA4CA21E4B06B00D5332F /* CircularCarousel.swift */,
1D0AA4C821E4B06B00D5332F /* CircularCarouselDataSource.swift */,
1D0AA4C921E4B06B00D5332F /* CircularCarouselDelegate.swift */,
1D0AA4BF21E4AFFF00D5332F /* Circulararousel.h */,
1D0AA4BF21E4AFFF00D5332F /* CircularCarousel.h */,
1D0AA4C021E4AFFF00D5332F /* Info.plist */,
1D24A57721E77F9200C61617 /* CircularCarousel+Scroll.swift */,
1D24A57921E7865900C61617 /* CircularCarousel+Gesture.swift */,
@@ -86,7 +86,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
1D0AA4C121E4AFFF00D5332F /* Circulararousel.h in Headers */,
1D0AA4C121E4AFFF00D5332F /* CircularCarousel.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1,19 +0,0 @@
//
// CircularCarousel.h
// CircularCarousel
//
// Created by Piotr Suwara on 8/1/19.
// Copyright © 2019 Piotr Suwara. All rights reserved.
//
#import <UIKit/UIKit.h>
//! Project version number for CircularCarousel.
FOUNDATION_EXPORT double CircularCarouselVersionNumber;
//! Project version string for CircularCarousel.
FOUNDATION_EXPORT const unsigned char CircularCarouselVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <CircularCarousel/PublicHeader.h>