Skip to content

Commit acbcf8e

Browse files
author
Michal Pyrka
committed
New Spectre example.
1 parent f049be5 commit acbcf8e

File tree

18 files changed

+191
-37
lines changed

18 files changed

+191
-37
lines changed

Example/MPParallaxView/Base.lproj/Main.storyboard

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,26 @@
4747
<constraint firstAttribute="height" constant="469" id="x3e-ag-a1r"/>
4848
</constraints>
4949
</view>
50+
<segmentedControl opaque="NO" alpha="0.5" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="ZHD-Mq-8gQ">
51+
<rect key="frame" x="221" y="564" width="159" height="29"/>
52+
<animations/>
53+
<segments>
54+
<segment title="Interstellar"/>
55+
<segment title="Spectre"/>
56+
</segments>
57+
<color key="tintColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
58+
<connections>
59+
<action selector="segmentedControlChanged:" destination="vXZ-lx-hvc" eventType="valueChanged" id="YEf-c7-mfg"/>
60+
</connections>
61+
</segmentedControl>
5062
</subviews>
5163
<animations/>
5264
<color key="backgroundColor" red="0.77647058823529413" green="0.84313725490196079" blue="0.8784313725490196" alpha="1" colorSpace="calibratedRGB"/>
5365
<constraints>
66+
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="ZHD-Mq-8gQ" secondAttribute="bottom" constant="8" id="Ey5-Ik-oRM"/>
5467
<constraint firstItem="C04-ud-3XR" firstAttribute="centerY" secondItem="kh9-bI-dsS" secondAttribute="centerY" id="SP4-Ch-dnA"/>
5568
<constraint firstItem="C04-ud-3XR" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="clf-bm-U6W"/>
69+
<constraint firstItem="ZHD-Mq-8gQ" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="lfC-C5-Jlw"/>
5670
</constraints>
5771
</view>
5872
</viewController>
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "007.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "james.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "lea.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "spectrelogo.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Loading

Example/MPParallaxView/ViewController.swift

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,48 @@
77
//
88

99
import UIKit
10+
import MPParallaxView
1011

1112
class ViewController: UIViewController {
1213

14+
@IBAction func segmentedControlChanged(sender: UISegmentedControl) {
15+
if sender.selectedSegmentIndex == 0 {
16+
setupInterstellar()
17+
} else {
18+
setupSpectre()
19+
}
20+
}
21+
22+
func setupInterstellar() {
23+
view.backgroundColor = UIColor(red: 198.0/255.0, green: 215.0/255.0, blue: 224.0/255.0, alpha: 1.0)
24+
let parallaxView = view.subviews.filter { $0 is MPParallaxView }.first as?MPParallaxView
25+
if let parallaxView = parallaxView {
26+
parallaxView.subviews.forEach { $0.removeFromSuperview() }
27+
interstellarAssets().forEach { parallaxView.addSubview($0) }
28+
parallaxView.prepareParallaxLook()
29+
}
30+
}
31+
32+
func setupSpectre() {
33+
view.backgroundColor = UIColor(red: 250.0/255.0, green: 250.0/255.0, blue: 250.0/255.0, alpha: 1.0)
34+
let parallaxView = view.subviews.filter { $0 is MPParallaxView }.first as?MPParallaxView
35+
if let parallaxView = parallaxView {
36+
parallaxView.subviews.forEach { $0.removeFromSuperview() }
37+
parallaxView.contentView.subviews.forEach { $0.removeFromSuperview() }
38+
let assets: [UIImageView] = spectreAssets()
39+
assets.forEach { parallaxView.addSubview($0) }
40+
parallaxView.prepareParallaxLook()
41+
if let logo = assets.first {
42+
logo.frame = CGRectOffset(logo.frame, -50, 0)
43+
}
44+
}
45+
}
46+
1347
override func viewDidLoad() {
1448
super.viewDidLoad()
15-
// Do any additional setup after loading the view, typically from a nib.
49+
UISegmentedControl.appearance().setTitleTextAttributes(
50+
[NSForegroundColorAttributeName : UIColor.whiteColor()],
51+
forState: .Selected)
1652
}
1753

1854
override func didReceiveMemoryWarning() {
@@ -22,3 +58,33 @@ class ViewController: UIViewController {
2258

2359
}
2460

61+
extension UIViewController {
62+
63+
func parallaxViewFrame() -> CGRect {
64+
return (view.subviews.filter { $0 is MPParallaxView }.first as? MPParallaxView)?.frame ?? CGRectZero
65+
}
66+
67+
func interstellarAssets() -> [UIImageView] {
68+
let interstellarImages = [("1", 0), ("2", 10), ("3", 2), ("4", 4), ("5", 12)]
69+
.flatMap { nameAndOffset -> UIImageView in
70+
let imageView = UIImageView(image: UIImage(named: nameAndOffset.0))
71+
imageView.tag = nameAndOffset.1
72+
return imageView
73+
}
74+
interstellarImages.forEach { $0.frame = parallaxViewFrame() }
75+
return interstellarImages
76+
}
77+
78+
func spectreAssets() -> [UIImageView] {
79+
let spectreImageViews = [("007", 30), ("lea", 4), ("james", 7), ("spectrelogo", 8)]
80+
.flatMap { nameAndOffset -> UIImageView in
81+
let imageView = UIImageView(image: UIImage(named: nameAndOffset.0))
82+
imageView.tag = nameAndOffset.1
83+
return imageView
84+
}
85+
spectreImageViews.forEach { $0.frame = parallaxViewFrame() }
86+
spectreImageViews.first?.frame = CGRectMake(parallaxViewFrame().origin.x, parallaxViewFrame().origin.y, parallaxViewFrame().size.width * 1.9, parallaxViewFrame().size.height)
87+
return spectreImageViews
88+
}
89+
}
90+

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- MPParallaxView (0.1.2)
2+
- MPParallaxView (0.1.3)
33

44
DEPENDENCIES:
55
- MPParallaxView (from `../`)
@@ -9,6 +9,6 @@ EXTERNAL SOURCES:
99
:path: "../"
1010

1111
SPEC CHECKSUMS:
12-
MPParallaxView: 8519d200202e6b443837876ff7848897f640e56b
12+
MPParallaxView: 49e04bf51d3c4246aa29c2a94fca60dca64f7245
1313

1414
COCOAPODS: 0.39.0

Example/Pods/Local Podspecs/MPParallaxView.podspec.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/MPParallaxView.xcscheme

Lines changed: 14 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/MPParallaxView/Info.plist

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MPParallaxView.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 = "MPParallaxView"
3-
s.version = "0.1.2"
3+
s.version = "0.1.3"
44
s.summary = "Apple TV Parallax effect in Swift."
55
s.description = <<-DESC
66
Show UIView with parallax effect from new Apple TV.

MPParallaxView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class MPParallaxView: UIView {
3232
}
3333
}
3434
}
35-
var contentView: UIView = UIView()
35+
public var contentView: UIView = UIView()
3636
public var cornerRadius: CGFloat {
3737
get {
3838
return self.layer.cornerRadius
@@ -59,7 +59,7 @@ public class MPParallaxView: UIView {
5959

6060
//MARK: Setup layout
6161

62-
func prepareParallaxLook() {
62+
public func prepareParallaxLook() {
6363
setupLayout()
6464
addShadowPath()
6565
setupContentView()
@@ -76,6 +76,7 @@ public class MPParallaxView: UIView {
7676
func setupContentView() {
7777
contentView.frame = bounds
7878
contentView.layer.masksToBounds = true
79+
contentView.backgroundColor = .whiteColor()
7980
subviews.forEach { subview in
8081
subview.translatesAutoresizingMaskIntoConstraints = true
8182
subview.removeFromSuperview()

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Apple TV Parallax effect in Swift.
44

5-
<img src="http://i.imgur.com/evBWf3c.gif" alt="MPParallaxView example">
5+
<img src="http://i.imgur.com/HpujAKj.gif" alt="MPParallaxView example">
66

77
## Usage
88

0 commit comments

Comments
 (0)