-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntroViewController.swift
70 lines (61 loc) · 2.93 KB
/
IntroViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// IntroViewController.swift
// Carousel
//
// Created by Marc Haumann on 2/11/16.
// Copyright © 2016 Marc Haumann. All rights reserved.
//
import UIKit
class IntroViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var tile1: UIImageView!
@IBOutlet weak var tile2: UIImageView!
@IBOutlet weak var tile3: UIImageView!
@IBOutlet weak var tile4: UIImageView!
@IBOutlet weak var tile5: UIImageView!
@IBOutlet weak var tile6: UIImageView!
@IBOutlet weak var introBackground: UIImageView!
@IBOutlet weak var introScrollView: UIScrollView!
let xInitials: [Float] = [48,269,254,166,50,144]
let yInitials: [Float] = [469,497,391,497,380,396]
let xOffsets: [Float] = [122,238,238,84,161,238]
let yOffsets: [Float] = [789,752,828,906,906,906]
let scales : [Float] = [1, 1.65, 1.7, 1.6, 1.65, 1.65]
let rotations : [Int] = [-10, -10, 10, 10, 10, -10]
override func viewDidLoad() {
super.viewDidLoad()
let tileArray = [tile1,tile2,tile3,tile4,tile5,tile6]
introScrollView.contentSize=introBackground.image!.size
introScrollView.delegate = self
for (index, tile) in EnumerateSequence(tileArray) {
let scale=CGFloat(scales[index])
tile.transform = CGAffineTransformMakeScale(scale, scale)
tile.transform = CGAffineTransformRotate(tile.transform,
CGFloat(Double(rotations[index]) * M_PI / 180))
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func scrollViewDidScroll(scrollView: UIScrollView) {
let tileArray = [tile1,tile2,tile3,tile4,tile5,tile6]
let scrollOffset=self.introScrollView.contentOffset.y
for (index, tile) in EnumerateSequence(tileArray) {
let scale = convertValue(scrollOffset, r1Min: -80, r1Max: 568, r2Min: CGFloat(scales[index]), r2Max: 1)
let rotation = convertValue(scrollOffset, r1Min: -80, r1Max: 568, r2Min: CGFloat(rotations[index]), r2Max: 0)
tile.transform = CGAffineTransformMakeScale(scale, scale)
tile.transform = CGAffineTransformRotate(tile.transform,
CGFloat(Double(rotation) * M_PI / 180))
tile.center.y = convertValue(scrollOffset, r1Min: -80, r1Max: 568, r2Min: CGFloat(yInitials[index]), r2Max: CGFloat(yOffsets[index]))
tile.center.x = convertValue(scrollOffset, r1Min: -80, r1Max: 568, r2Min: CGFloat(xInitials[index]), r2Max: CGFloat(xOffsets[index]))
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}