Skip to content

Commit c55d883

Browse files
committed
- resetting affine transforms before setting frames and applying them back later (fixes SCSafariPageViewController problems)
- converted Swift demo to Swift 3 - updated demo projects to work with latest cocoapods
1 parent a4facd0 commit c55d883

File tree

7 files changed

+215
-64
lines changed

7 files changed

+215
-64
lines changed

Demo/Podfile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
source 'https://github.com/CocoaPods/Specs.git'
22

3-
pod 'SCScrollView', '~> 1.1'
3+
def shared_pods
4+
pod 'SCScrollView', '~> 1.1'
5+
end
6+
7+
target 'ObjCDemo' do
8+
shared_pods
9+
end
10+
11+
target 'Tests' do
12+
shared_pods
13+
end
14+
15+
target 'SwiftDemo' do
16+
shared_pods
17+
end

Demo/SCPageViewController.xcodeproj/project.pbxproj

Lines changed: 159 additions & 26 deletions
Large diffs are not rendered by default.

Demo/SwiftDemo/AppDelegate.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

1616

17-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
17+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1818
// Override point for customization after application launch.
1919

20-
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
20+
self.window = UIWindow(frame: UIScreen.main.bounds)
2121
self.window?.rootViewController = RootViewController()
2222
self.window?.makeKeyAndVisible()
2323

2424
return true
2525
}
2626

27-
func applicationWillResignActive(application: UIApplication) {
27+
func applicationWillResignActive(_ application: UIApplication) {
2828
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
2929
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
3030
}
3131

32-
func applicationDidEnterBackground(application: UIApplication) {
32+
func applicationDidEnterBackground(_ application: UIApplication) {
3333
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
3434
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
3535
}
3636

37-
func applicationWillEnterForeground(application: UIApplication) {
37+
func applicationWillEnterForeground(_ application: UIApplication) {
3838
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
3939
}
4040

41-
func applicationDidBecomeActive(application: UIApplication) {
41+
func applicationDidBecomeActive(_ application: UIApplication) {
4242
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
4343
}
4444

45-
func applicationWillTerminate(application: UIApplication) {
45+
func applicationWillTerminate(_ application: UIApplication) {
4646
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
4747
}
4848

Demo/SwiftDemo/MainViewController.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import UIKit
1010

1111
protocol MainViewControllerDelegate {
12-
func mainViewControllerDidChangeLayouterType(mainViewController: MainViewController)
12+
func mainViewControllerDidChangeLayouterType(_ mainViewController: MainViewController)
1313
}
1414

1515
enum PageLayouterType : Int {
16-
case Plain, Sliding, Parallax, Cards
16+
case plain, sliding, parallax, cards
1717
}
1818

1919
class MainViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
@@ -31,30 +31,30 @@ class MainViewController: UIViewController, UIPickerViewDataSource, UIPickerView
3131
super.viewDidLoad()
3232
}
3333

34-
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
34+
func numberOfComponents(in pickerView: UIPickerView) -> Int {
3535
return 1
3636
}
3737

38-
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
38+
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
3939
return 4
4040
}
4141

42-
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
42+
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
4343

4444
let layouterType = PageLayouterType.init(rawValue: row)!
4545
switch(layouterType) {
46-
case .Plain:
46+
case .plain:
4747
return "Plain"
48-
case .Sliding:
48+
case .sliding:
4949
return "Sliding"
50-
case .Parallax:
50+
case .parallax:
5151
return "Parallax"
52-
case .Cards:
52+
case .cards:
5353
return "Cards"
5454
}
5555
}
5656

57-
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
57+
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
5858
layouterType = PageLayouterType.init(rawValue: row)!
5959
delegate?.mainViewControllerDidChangeLayouterType(self)
6060
}

Demo/SwiftDemo/RootViewController.swift

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ class RootViewController : UIViewController , SCPageViewControllerDataSource, SC
1717

1818
super.viewDidLoad()
1919

20-
for(var i = 0 ; i<5; i++) {
20+
for _ in 1...5 {
2121
viewControllers.append(nil);
22-
2322
}
2423

2524
self.pageViewController.setLayouter(SCPageLayouter(), animated: false, completion: nil)
26-
self.pageViewController.easingFunction = SCEasingFunction(type: SCEasingFunctionType.Linear)
25+
self.pageViewController.easingFunction = SCEasingFunction(type: SCEasingFunctionType.linear)
2726

2827
//self.pageViewController.scrollView.maximumNumberOfTouches = 1;
2928
//self.pageViewController.scrollView.panGestureRecognizer.minimumNumberOfTouches = 2;
@@ -34,16 +33,16 @@ class RootViewController : UIViewController , SCPageViewControllerDataSource, SC
3433
self.addChildViewController(self.pageViewController)
3534
self.pageViewController.view.frame = self.view.bounds
3635
self.view.addSubview(self.pageViewController.view)
37-
self.pageViewController.didMoveToParentViewController(self)
36+
self.pageViewController.didMove(toParentViewController: self)
3837
}
3938

4039
//MARK: - SCPageViewControllerDataSource
4140

42-
func numberOfPagesInPageViewController(pageViewController: SCPageViewController!) -> UInt {
41+
func numberOfPages(in pageViewController: SCPageViewController!) -> UInt {
4342
return UInt(self.viewControllers.count)
4443
}
4544

46-
func pageViewController(pageViewController: SCPageViewController!, viewControllerForPageAtIndex pageIndex: UInt) -> UIViewController! {
45+
func pageViewController(_ pageViewController: SCPageViewController!, viewControllerForPageAt pageIndex: UInt) -> UIViewController! {
4746

4847

4948
if let viewController = self.viewControllers[Int(pageIndex)] {
@@ -69,22 +68,22 @@ class RootViewController : UIViewController , SCPageViewControllerDataSource, SC
6968

7069
//MARK: - SCPageViewControllerDelegate
7170

72-
func pageViewController(pageViewController: SCPageViewController!, didNavigateToOffset offset: CGPoint) {
73-
71+
func pageViewController(_ pageViewController: SCPageViewController!, didNavigateToOffset offset: CGPoint) {
72+
7473
func layouterToType(layouter: SCPageLayouterProtocol) -> PageLayouterType {
7574
switch layouter {
7675
case is SCSlidingPageLayouter:
77-
return PageLayouterType.Sliding
76+
return PageLayouterType.sliding
7877
case is SCParallaxPageLayouter:
79-
return PageLayouterType.Parallax
78+
return PageLayouterType.parallax
8079
case is SCCardsPageLayouter:
81-
return PageLayouterType.Cards
80+
return PageLayouterType.cards
8281
default:
83-
return PageLayouterType.Plain
82+
return PageLayouterType.plain
8483
}
8584
}
8685

87-
let layouterType = layouterToType(self.pageViewController.layouter!);
86+
let layouterType = layouterToType(layouter: self.pageViewController.layouter!);
8887

8988
for optionalValue in self.viewControllers {
9089
if(optionalValue != nil) {
@@ -97,16 +96,16 @@ class RootViewController : UIViewController , SCPageViewControllerDataSource, SC
9796

9897
//MARK: - MainViewControllerDelegate
9998

100-
func mainViewControllerDidChangeLayouterType(mainViewController: MainViewController) {
99+
func mainViewControllerDidChangeLayouterType(_ mainViewController: MainViewController) {
101100
switch(mainViewController.layouterType!) {
102-
case .Plain:
101+
case .plain:
103102
self.pageViewController.setLayouter(SCPageLayouter(), animated: false, completion: nil)
104-
case .Sliding:
103+
case .sliding:
105104
self.pageViewController.setLayouter(SCSlidingPageLayouter(), animated: true, completion: nil)
106-
case .Parallax:
105+
case .parallax:
107106
self.pageViewController.setLayouter(SCParallaxPageLayouter(), animated: true, completion: nil)
108-
case .Cards:
107+
case .cards:
109108
self.pageViewController.setLayouter(SCCardsPageLayouter(), animated: true, completion: nil)
110109
}
111110
}
112-
}
111+
}

SCPageViewController.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'SCPageViewController'
3-
s.version = '2.0.8'
3+
s.version = '2.0.9'
44
s.platform = :ios
55
s.ios.deployment_target = '5.0'
66

SCPageViewController/SCPageViewController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,9 @@ - (void)_updateFramesAndTriggerAppearanceCallbacks
592592
}
593593

594594
remainder = [self _subtractRect:intersection fromRect:remainder withEdge:edge];
595+
596+
CATransform3D previousTransform = viewController.view.layer.transform;
597+
[self _setAnimatableSublayerTransform:CATransform3DIdentity forViewController:viewController];
595598

596599
// Finally, trigger appearance callbacks and new frame
597600
if(visible && ![self.visibleControllers containsObject:viewController]) {
@@ -624,6 +627,8 @@ - (void)_updateFramesAndTriggerAppearanceCallbacks
624627
pageViewController:self];
625628

626629
[self _setAnimatableSublayerTransform:transform forViewController:viewController];
630+
} else {
631+
[self _setAnimatableSublayerTransform:previousTransform forViewController:viewController];
627632
}
628633
}];
629634
}

0 commit comments

Comments
 (0)