-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix a few bugs with the new snapshot system, add videoPlayer example
- Loading branch information
Showing
28 changed files
with
371 additions
and
429 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
Examples/HeroExamples/Assets.xcassets/bigbuckbunny.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "poster.jpg", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
231 changes: 0 additions & 231 deletions
231
Examples/HeroExamples/Base.lproj/AppleHomePage.storyboard
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Examples/HeroExamples/Examples/VideoPlayer/VideoPlayer.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16C68" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Jlr-UW-RBl"> | ||
<device id="retina4_7" orientation="portrait"> | ||
<adaptation id="fullscreen"/> | ||
</device> | ||
<dependencies> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Video Player View Controller--> | ||
<scene sceneID="1nH-rV-HNC"> | ||
<objects> | ||
<viewController id="Jlr-UW-RBl" customClass="VideoPlayerViewController" customModule="HeroExamples" customModuleProvider="target" sceneMemberID="viewController"> | ||
<layoutGuides> | ||
<viewControllerLayoutGuide type="top" id="hf8-Fp-Md5"/> | ||
<viewControllerLayoutGuide type="bottom" id="GrU-da-mkb"/> | ||
</layoutGuides> | ||
<view key="view" contentMode="scaleToFill" id="sJC-Pq-CA9"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="z6Y-4L-zqp"> | ||
<rect key="frame" x="8" y="28" width="48" height="48"/> | ||
<constraints> | ||
<constraint firstAttribute="height" constant="48" id="9CC-aa-S8X"/> | ||
<constraint firstAttribute="width" constant="48" id="Ny5-Ce-hwc"/> | ||
</constraints> | ||
<color key="tintColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/> | ||
<state key="normal" image="ic_keyboard_arrow_down"/> | ||
<userDefinedRuntimeAttributes> | ||
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadius"> | ||
<real key="value" value="24"/> | ||
</userDefinedRuntimeAttribute> | ||
<userDefinedRuntimeAttribute type="string" keyPath="heroModifierString" value="fade translate(0, -150)"/> | ||
<userDefinedRuntimeAttribute type="string" keyPath="heroID" value="back"/> | ||
</userDefinedRuntimeAttributes> | ||
<connections> | ||
<action selector="hero_dismissViewController" destination="wAT-Zx-dlV" eventType="touchUpInside" id="eY3-Hc-QXA"/> | ||
</connections> | ||
</button> | ||
</subviews> | ||
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/> | ||
<constraints> | ||
<constraint firstItem="z6Y-4L-zqp" firstAttribute="top" secondItem="hf8-Fp-Md5" secondAttribute="bottom" constant="8" id="3iS-CQ-7V0"/> | ||
<constraint firstItem="z6Y-4L-zqp" firstAttribute="leading" secondItem="sJC-Pq-CA9" secondAttribute="leading" constant="8" id="x8a-3B-voa"/> | ||
</constraints> | ||
</view> | ||
<userDefinedRuntimeAttributes> | ||
<userDefinedRuntimeAttribute type="boolean" keyPath="isHeroEnabled" value="YES"/> | ||
</userDefinedRuntimeAttributes> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="wAT-Zx-dlV" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="20" y="-145.27736131934034"/> | ||
</scene> | ||
</scenes> | ||
<resources> | ||
<image name="ic_keyboard_arrow_down" width="24" height="24"/> | ||
</resources> | ||
</document> |
88 changes: 88 additions & 0 deletions
88
Examples/HeroExamples/Examples/VideoPlayer/VideoPlayerViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2016 Luke Zhao <[email protected]> | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import UIKit | ||
import Hero | ||
import AVKit | ||
import AVFoundation | ||
|
||
class AVPlayerView: UIView { | ||
override class var layerClass: Swift.AnyClass { | ||
return AVPlayerLayer.self | ||
} | ||
} | ||
|
||
class VideoPlayerViewController: UIViewController { | ||
var playerView: UIView! | ||
var panGR: UIPanGestureRecognizer! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
let player = AVPlayer(url: URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!) | ||
|
||
playerView = AVPlayerView(frame: view.bounds) | ||
(playerView.layer as! AVPlayerLayer).player = player | ||
playerView.heroID = "videoPlayer" | ||
playerView.heroModifiers = [.useNoSnapshot, .useScaleBasedSizeChange] | ||
view.insertSubview(playerView, at: 0) | ||
|
||
panGR = UIPanGestureRecognizer(target: self, action: #selector(pan)) | ||
view.addGestureRecognizer(panGR) | ||
|
||
// skip the initial splash screen of the video | ||
player.seek(to: CMTimeMakeWithSeconds(0.35, 1000), toleranceBefore: kCMTimeZero, toleranceAfter: kCMTimeZero) | ||
player.play() | ||
} | ||
|
||
func pan() { | ||
let translation = panGR.translation(in: nil) | ||
let progress = translation.y / 2 / view.bounds.height | ||
switch panGR.state { | ||
case .began: | ||
hero_dismissViewController() | ||
case .changed: | ||
Hero.shared.update(progress: Double(progress)) | ||
let currentPos = CGPoint(x: translation.x + view.center.x, y: translation.y + view.center.y) | ||
Hero.shared.apply(modifiers: [.position(currentPos)], to: playerView) | ||
default: | ||
if progress + panGR.velocity(in: nil).y / view.bounds.height > 0.3 { | ||
Hero.shared.end() | ||
} else { | ||
Hero.shared.cancel() | ||
} | ||
} | ||
} | ||
|
||
override func viewWillLayoutSubviews() { | ||
super.viewWillLayoutSubviews() | ||
playerView.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.width / 16 * 9) | ||
playerView.center = view.center | ||
} | ||
|
||
override func viewDidAppear(_ animated: Bool) { | ||
super.viewDidAppear(animated) | ||
// must re-insert the playerView since we used .useNoSnapshot modifier on it. | ||
// Hero will take it out of the view hierarchy during the transition. | ||
playerView.frame = view.bounds | ||
view.insertSubview(playerView, at: 0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.