11 changed files with 458 additions and 127 deletions
-
4Podfile
-
28kplayer.xcodeproj/project.pbxproj
-
18kplayer/Base.lproj/Main.storyboard
-
32kplayer/core/MediaItem.swift
-
8kplayer/core/NetworkManager.swift
-
8kplayer/detail/DetailViewController.swift
-
23kplayer/detail/ItemCell.swift
-
170kplayer/detail/VideoPlayerController.swift
-
117kplayer/master/MasterViewController.swift
-
150kplayer/photo/MediaPhotoController.swift
-
17kplayer/util/LayoutTools.swift
@ -0,0 +1,150 @@ |
|||
// |
|||
// Created by Marco Schmickler on 04.06.15. |
|||
// Copyright (c) 2015 Marco Schmickler. All rights reserved. |
|||
// |
|||
|
|||
import Foundation |
|||
import Nimbus |
|||
import Haneke |
|||
|
|||
class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollViewDataSource, NIPhotoScrubberViewDataSource { |
|||
|
|||
var items = [MediaItem]() |
|||
var completionHandler: ((Void) -> Void)? |
|||
|
|||
override func viewDidLoad() { |
|||
super.viewDidLoad() |
|||
|
|||
let backButton = UIBarButtonItem(barButtonSystemItem: .Cancel, target: self, action: Selector("back")) |
|||
navigationItem.leftBarButtonItems = [backButton] |
|||
|
|||
setChromeVisibility(true, animated: true) |
|||
|
|||
self.photoAlbumView.reloadData(); |
|||
self.photoScrubberView.reloadData(); |
|||
} |
|||
|
|||
func back() { |
|||
completionHandler!() |
|||
} |
|||
|
|||
override func loadView() { |
|||
super.loadView() |
|||
photoAlbumView.dataSource = self |
|||
photoScrubberView.dataSource = self |
|||
|
|||
toolbarIsTranslucent = true |
|||
hidesChromeWhenScrolling = true |
|||
chromeCanBeHidden = true |
|||
scrubberIsEnabled = true |
|||
|
|||
|
|||
// Toolbar Setup |
|||
let bounds = self.view.bounds; |
|||
let toolbarHeight = CGFloat(120.0) |
|||
toolbar.frame = CGRectMake(0, bounds.size.height - toolbarHeight, bounds.size.width, toolbarHeight); |
|||
|
|||
photoAlbumView.zoomingAboveOriginalSizeIsEnabled = true; |
|||
|
|||
// This title will be displayed until we get the results back for the album information. |
|||
self.title = "loading" |
|||
|
|||
// self.photoAlbumView.loadingImage = UIImage(named: "Kirschkeks-256x256.png") |
|||
println("\(count(items))") |
|||
} |
|||
|
|||
func photoAlbumScrollView(photoAlbumScrollView: NIPhotoAlbumScrollView!, photoAtIndex: Int, photoSize: UnsafeMutablePointer<NIPhotoScrollViewPhotoSize>, |
|||
isLoading: UnsafeMutablePointer<ObjCBool>, originalPhotoDimensions: UnsafeMutablePointer<CGSize>) -> UIImage! { |
|||
let c = count(items) |
|||
println ("Index: \(photoAtIndex) of \(c)") |
|||
let newItem = items[photoAtIndex] |
|||
let URL = NSURL(string: newItem.imageUrlAbsolute)! |
|||
println (newItem.imageUrlAbsolute) |
|||
var image: UIImage? = nil |
|||
|
|||
var size = NIPhotoScrollViewPhotoSizeUnknown |
|||
|
|||
Shared.imageCache.fetch(URL: URL).onSuccess { |
|||
i in |
|||
image = i |
|||
size = NIPhotoScrollViewPhotoSizeOriginal |
|||
self.photoAlbumView.didLoadPhoto(image, atIndex:photoAtIndex, photoSize:size) |
|||
} |
|||
|
|||
if let i = image { |
|||
isLoading[0] = false |
|||
} |
|||
else { |
|||
let URL = NSURL(string: newItem.thumbUrlAbsolute)! |
|||
println (newItem.thumbUrlAbsolute) |
|||
var image: UIImage? = nil |
|||
|
|||
Shared.imageCache.fetch(URL: URL).onSuccess { |
|||
i in |
|||
image = i |
|||
size = NIPhotoScrollViewPhotoSizeThumbnail |
|||
self.photoAlbumView.didLoadPhoto(image, atIndex:photoAtIndex, photoSize:size) |
|||
} |
|||
isLoading[0] = true |
|||
} |
|||
photoSize[0] = size |
|||
|
|||
// if image == nil { return UIImage(named: "Kirschkeks-256x256.png") } |
|||
// self.photoAlbumView.didLoadPhoto(image, atIndex:photoAtIndex, photoSize:size) |
|||
return image |
|||
} |
|||
|
|||
func numberOfPagesInPagingScrollView(pagingScrollView: NIPagingScrollView) -> Int { |
|||
let c = count(items) |
|||
return c |
|||
} |
|||
|
|||
/** |
|||
* Fetches a page that will be displayed at the given page index. |
|||
* |
|||
* You should always try to reuse pages by calling dequeueReusablePageWithIdentifier: on the |
|||
* paging scroll view before allocating a new page. |
|||
*/ |
|||
func pagingScrollView(pagingScrollView: NIPagingScrollView, pageViewForIndex: Int) -> UIView { |
|||
let view = photoAlbumView.pagingScrollView(pagingScrollView, pageViewForIndex: pageViewForIndex) as! NIPhotoScrollView |
|||
|
|||
view.maximumScale = 3; |
|||
|
|||
|
|||
return view; |
|||
} |
|||
|
|||
func numberOfPhotosInScrubberView(photoScrubberView: NIPhotoScrubberView!) -> Int { |
|||
let c = count(items) |
|||
return c |
|||
} |
|||
|
|||
/** |
|||
* Fetch the thumbnail image for the given photo index. |
|||
* |
|||
* Please read and understand the performance considerations for this data source. |
|||
*/ |
|||
func photoScrubberView(photoScrubberView: NIPhotoScrubberView!, thumbnailAtIndex thumbnailIndex: Int) -> UIImage! { |
|||
if thumbnailIndex < 0 { |
|||
return nil |
|||
} |
|||
|
|||
let c = count(items) |
|||
println ("Index: \(thumbnailIndex) of \(c)") |
|||
let newItem = items[thumbnailIndex] |
|||
let URL = NSURL(string: newItem.thumbUrlAbsolute)! |
|||
|
|||
var image: UIImage? = nil |
|||
|
|||
Shared.imageCache.fetch(URL: URL).onSuccess { |
|||
i in |
|||
image = i |
|||
self.photoScrubberView.didLoadThumbnail(i, atIndex: thumbnailIndex); |
|||
} |
|||
// if image == nil { return UIImage(named: "Kirschkeks-256x256.png") } |
|||
|
|||
return image |
|||
} |
|||
|
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue