Skip to content

Commit

Permalink
Refractions.
Browse files Browse the repository at this point in the history
  • Loading branch information
WenchaoD committed Mar 28, 2017
1 parent 72adbab commit f640a03
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ class PageControlExampleViewController: UIViewController,UITableViewDataSource,U
heartPath.addArc(
withCenter: CGPoint(x: width*0.25,y: height*0.25),
radius: width * 0.25,
startAngle: CGFloat(M_PI),
startAngle: .pi,
endAngle: 0,
clockwise: true
)
heartPath.addArc(
withCenter: CGPoint(x: width*0.75, y: height*0.25),
radius: width * 0.25,
startAngle: CGFloat(M_PI),
startAngle: .pi,
endAngle: 0,
clockwise: true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TransformerExampleViewController: UIViewController,FSPagerViewDataSource,F
let type = self.transformerTypes[typeIndex]
self.pagerView.transformer = FSPagerViewTransformer(type:type)
switch type {
case .none, .crossFading, .zoomOut, .depth:
case .crossFading, .zoomOut, .depth:
self.pagerView.itemSize = .zero // 'Zero' means fill the size of parent
case .linear, .overlap:
let transform = CGAffineTransform(scaleX: 0.6, y: 0.75)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0830"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 0830;
ORGANIZATIONNAME = "Wenchao Ding";
TargetAttributes = {
F9C694481E40C6C1007084B6 = {
Expand Down Expand Up @@ -490,6 +490,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0830"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ - (void)sliderValueChanged:(UISlider *)sender
}
break;
}
case 3: {
case 2: {
self.pageControl.interitemSpacing = 6.0 + sender.value*10.0; // [6 - 16]
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ - (void)setTypeIndex:(NSInteger)typeIndex
break;
}
default:
type = FSPagerViewTransformerTypeZoomOut;
break;
}
self.pagerView.transformer = [[FSPagerViewTransformer alloc] initWithType:type];
Expand Down
18 changes: 5 additions & 13 deletions Sources/FSPageViewTransformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import UIKit

@objc
public enum FSPagerViewTransformerType: Int {
case none
case crossFading
case zoomOut
case depth
Expand All @@ -25,13 +24,12 @@ public enum FSPagerViewTransformerType: Int {
open class FSPagerViewTransformer: NSObject {

open internal(set) weak var pagerView: FSPagerView?
open internal(set) var type: FSPagerViewTransformerType = .none
open internal(set) var type: FSPagerViewTransformerType

open var minimumScale: CGFloat = 0.65
open var minimumAlpha: CGFloat = 0.6

public init(type: FSPagerViewTransformerType) {
super.init()
self.type = type
switch type {
case .zoomOut:
Expand All @@ -43,10 +41,6 @@ open class FSPagerViewTransformer: NSObject {
}
}

public override init () {
super.init()
}

// Apply transform to attributes - zIndex: Int, frame: CGRect, alpha: CGFloat, transform: CGAffineTransform or transform3D: CATransform3D.
open func applyTransform(to attributes: FSPagerViewLayoutAttributes) {
guard let pagerView = self.pagerView else {
Expand All @@ -56,8 +50,6 @@ open class FSPagerViewTransformer: NSObject {
let scrollDirection = pagerView.scrollDirection
let itemSpacing = (scrollDirection == .horizontal ? attributes.bounds.width : attributes.bounds.height) + self.proposedInteritemSpacing()
switch self.type {
case .none:
break
case .crossFading:
var zIndex = 0
var alpha: CGFloat = 0
Expand Down Expand Up @@ -172,7 +164,7 @@ open class FSPagerViewTransformer: NSObject {
return
}
let position = min(max(-position,-1) ,1)
let rotation = sin(position*CGFloat(M_PI_2)) * CGFloat(M_PI_4)*1.5
let rotation = sin(position*(.pi)*0.5)*(.pi)*0.25*1.5
let translationZ = -itemSpacing * 0.5 * abs(position)
var transform3D = CATransform3DIdentity
transform3D.m34 = -0.002
Expand All @@ -192,7 +184,7 @@ open class FSPagerViewTransformer: NSObject {
case -5 ... 5:
let itemSpacing = attributes.bounds.width+self.proposedInteritemSpacing()
let count: CGFloat = 14
let circle: CGFloat = CGFloat(M_PI) * 2.0
let circle: CGFloat = .pi * 2.0
let radius = itemSpacing * count / circle
let ty = radius * (self.type == .ferrisWheel ? 1 : -1)
let theta = circle / count
Expand All @@ -215,7 +207,7 @@ open class FSPagerViewTransformer: NSObject {
attributes.alpha = 1
attributes.zIndex = Int((1-position) * CGFloat(10))
let direction: CGFloat = position < 0 ? 1 : -1
let theta = position * CGFloat(M_PI_2) * (scrollDirection == .horizontal ? 1 : -1)
let theta = position * .pi * 0.5 * (scrollDirection == .horizontal ? 1 : -1)
let radius = scrollDirection == .horizontal ? attributes.bounds.width : attributes.bounds.height
var transform3D = CATransform3DIdentity
transform3D.m34 = -0.002
Expand Down Expand Up @@ -262,7 +254,7 @@ open class FSPagerViewTransformer: NSObject {
guard scrollDirection == .horizontal else {
return 0
}
return -pagerView.itemSize.width * sin(CGFloat(M_PI_4)/4.0*3.0)
return -pagerView.itemSize.width * sin(.pi*0.25*0.25*3.0)
case .ferrisWheel,.invertedFerrisWheel:
guard scrollDirection == .horizontal else {
return 0
Expand Down

0 comments on commit f640a03

Please sign in to comment.