diff --git a/README.md b/README.md index 17ef145..4c758d5 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Simple PhotoBrowser/Viewer inspired by facebook, twitter photo browsers written - Minimalistic Facebook-like interface, swipe up/down to dismiss - has simple ability to custom photobrowser. (hide/show statusbar, some toolbar for controls, swipe control) - Handling and caching photos from web +- Landscape handling. ![sample](Screenshots/example01.gif) diff --git a/SKPhotoBrowser.xcodeproj/project.pbxproj b/SKPhotoBrowser.xcodeproj/project.pbxproj index 0dc4fdf..5d0e42e 100644 --- a/SKPhotoBrowser.xcodeproj/project.pbxproj +++ b/SKPhotoBrowser.xcodeproj/project.pbxproj @@ -8,14 +8,14 @@ /* Begin PBXBuildFile section */ 8909B5341BC791280060A053 /* SKPhotoBrowser.h in Headers */ = {isa = PBXBuildFile; fileRef = 8909B5331BC791280060A053 /* SKPhotoBrowser.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 8909B5431BC791510060A053 /* SKCaptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B53B1BC791510060A053 /* SKCaptionView.swift */; settings = {ASSET_TAGS = (); }; }; - 8909B5441BC791510060A053 /* SKDetectingImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B53C1BC791510060A053 /* SKDetectingImageView.swift */; settings = {ASSET_TAGS = (); }; }; - 8909B5451BC791510060A053 /* SKDetectingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B53D1BC791510060A053 /* SKDetectingView.swift */; settings = {ASSET_TAGS = (); }; }; - 8909B5461BC791510060A053 /* SKIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B53E1BC791510060A053 /* SKIndicatorView.swift */; settings = {ASSET_TAGS = (); }; }; - 8909B5471BC791510060A053 /* SKPhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B53F1BC791510060A053 /* SKPhoto.swift */; settings = {ASSET_TAGS = (); }; }; - 8909B5491BC791510060A053 /* SKPhotoBrowser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B5411BC791510060A053 /* SKPhotoBrowser.swift */; settings = {ASSET_TAGS = (); }; }; - 8909B54A1BC791510060A053 /* SKZoomingScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B5421BC791510060A053 /* SKZoomingScrollView.swift */; settings = {ASSET_TAGS = (); }; }; - 8909B54D1BC7916E0060A053 /* SKPhotoBrowser.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 8909B54C1BC7916E0060A053 /* SKPhotoBrowser.bundle */; settings = {ASSET_TAGS = (); }; }; + 8909B5431BC791510060A053 /* SKCaptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B53B1BC791510060A053 /* SKCaptionView.swift */; }; + 8909B5441BC791510060A053 /* SKDetectingImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B53C1BC791510060A053 /* SKDetectingImageView.swift */; }; + 8909B5451BC791510060A053 /* SKDetectingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B53D1BC791510060A053 /* SKDetectingView.swift */; }; + 8909B5461BC791510060A053 /* SKIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B53E1BC791510060A053 /* SKIndicatorView.swift */; }; + 8909B5471BC791510060A053 /* SKPhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B53F1BC791510060A053 /* SKPhoto.swift */; }; + 8909B5491BC791510060A053 /* SKPhotoBrowser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B5411BC791510060A053 /* SKPhotoBrowser.swift */; }; + 8909B54A1BC791510060A053 /* SKZoomingScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B5421BC791510060A053 /* SKZoomingScrollView.swift */; }; + 8909B54D1BC7916E0060A053 /* SKPhotoBrowser.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 8909B54C1BC7916E0060A053 /* SKPhotoBrowser.bundle */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -314,6 +314,7 @@ 8909B53A1BC791280060A053 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/SKPhotoBrowser/SKCaptionView.swift b/SKPhotoBrowser/SKCaptionView.swift index 07f8d96..445d4d2 100644 --- a/SKPhotoBrowser/SKCaptionView.swift +++ b/SKPhotoBrowser/SKCaptionView.swift @@ -14,9 +14,9 @@ public class SKCaptionView: UIView { var screenWidth :CGFloat { return screenBound.size.width } var screenHeight:CGFloat { return screenBound.size.height } - var photo:SKPhoto! - var photoLabel:UILabel! - var photoLabelPadding:CGFloat = 10 + private var photo:SKPhoto! + private var photoLabel:UILabel! + private var photoLabelPadding:CGFloat = 10 required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) @@ -35,6 +35,7 @@ public class SKCaptionView: UIView { func setup() { opaque = false + autoresizingMask = [.FlexibleWidth, .FlexibleTopMargin, .FlexibleRightMargin, .FlexibleLeftMargin] // setup background first let fadeView = UIView(frame: CGRectMake(0, -100, screenWidth, bounds.size.height)) @@ -49,10 +50,10 @@ public class SKCaptionView: UIView { photoLabel.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] photoLabel.opaque = false photoLabel.backgroundColor = .clearColor() + photoLabel.textColor = .whiteColor() photoLabel.textAlignment = .Center photoLabel.lineBreakMode = .ByWordWrapping photoLabel.numberOfLines = 3 - photoLabel.textColor = .whiteColor() photoLabel.shadowColor = UIColor(white: 0.0, alpha: 0.5) photoLabel.shadowOffset = CGSizeMake(0.0, 1.0) photoLabel.font = UIFont.systemFontOfSize(17.0) diff --git a/SKPhotoBrowser/SKDetectingImageView.swift b/SKPhotoBrowser/SKDetectingImageView.swift index 9306bae..a0b467d 100644 --- a/SKPhotoBrowser/SKDetectingImageView.swift +++ b/SKPhotoBrowser/SKDetectingImageView.swift @@ -15,6 +15,8 @@ import UIKit class SKDetectingImageView:UIImageView{ + weak var delegate:SKDetectingImageViewDelegate? + required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } @@ -24,8 +26,6 @@ class SKDetectingImageView:UIImageView{ userInteractionEnabled = true } - weak var delegate:SKDetectingImageViewDelegate? - override func touchesEnded(touches: Set, withEvent event: UIEvent?) { super.touchesEnded(touches, withEvent: event) diff --git a/SKPhotoBrowser/SKDetectingView.swift b/SKPhotoBrowser/SKDetectingView.swift index 957c5ec..ce161c3 100644 --- a/SKPhotoBrowser/SKDetectingView.swift +++ b/SKPhotoBrowser/SKDetectingView.swift @@ -33,6 +33,7 @@ class SKDetectingView:UIView{ func handleSingleTap(touch: UITouch) { delegate?.handleSingleTap(self, touch: touch) } + func handleDoubleTap(touch: UITouch) { delegate?.handleDoubleTap(self, touch: touch) } diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index e148cb2..9307ef8 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -19,7 +19,9 @@ let SKPHOTO_LOADING_DID_END_NOTIFICATION = "photoLoadingDidEndNotification" // MARK: - SKPhotoBrowser public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate{ - final let pageIndexTagOffset = 1000 + final let pageIndexTagOffset:Int = 1000 + // animation property + final let animationDuration:Double = 0.35 // device property final let screenBound = UIScreen.mainScreen().bounds @@ -34,22 +36,45 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate{ public var isForceStatusBarHidden:Bool = false // tool for controls - var applicationWindow:UIWindow! - var toolBar:UIToolbar! - var toolCounterLabel:UILabel! - var toolCounterButton:UIBarButtonItem! - var toolPreviousButton:UIBarButtonItem! - var toolNextButton:UIBarButtonItem! - var pagingScrollView:UIScrollView! - var panGesture:UIPanGestureRecognizer! - var doneButton:UIButton! - var doneButtonShowFrame:CGRect = CGRectMake(5, 5, 44, 44) - var doneButtonHideFrame:CGRect = CGRectMake(5, -20, 44, 44) + private var applicationWindow:UIWindow! + private var toolBar:UIToolbar! + private var toolCounterLabel:UILabel! + private var toolCounterButton:UIBarButtonItem! + private var toolPreviousButton:UIBarButtonItem! + private var toolNextButton:UIBarButtonItem! + private var pagingScrollView:UIScrollView! + private var panGesture:UIPanGestureRecognizer! + private var doneButton:UIButton! + private var doneButtonShowFrame:CGRect = CGRectMake(5, 5, 44, 44) + private var doneButtonHideFrame:CGRect = CGRectMake(5, -20, 44, 44) // photo's paging - var visiblePages:Set = Set() - var initialPageIndex:Int = 0 - var currentPageIndex:Int = 0 + private var visiblePages:Set = Set() + private var initialPageIndex:Int = 0 + private var currentPageIndex:Int = 0 + + // senderView's property + private var senderViewForAnimation:UIView? + private var senderViewOriginalFrame:CGRect = CGRectZero + private var senderOriginImage:UIImage! + + private var resizableImageView:UIImageView = UIImageView() + + // for status check property + private var isDraggingPhoto:Bool = false + private var isViewActive:Bool = false + private var isPerformingLayout:Bool = false + private var isStatusBarOriginallyHidden:Bool = false + + // scroll property + private var firstX:CGFloat = 0.0 + private var firstY:CGFloat = 0.0 + + // timer + private var controlVisibilityTimer:NSTimer! + + // delegate + public weak var delegate: SKPhotoBrowserDelegate? // photos var photos:[SKPhoto] = [SKPhoto]() @@ -57,31 +82,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate{ return photos.count } - // senderView's property - var senderViewForAnimation:UIView? - var senderViewOriginalFrame:CGRect = CGRectZero - var senderOriginImage:UIImage! - - // animation property - let animationDuration:Double = 0.35 - var resizableImageView:UIImageView = UIImageView() - - // for status check - var isDraggingPhoto:Bool = false - var isViewActive:Bool = false - var isPerformingLayout:Bool = false - var isStatusBarOriginallyHidden:Bool = false - - // scroll property - var firstX:CGFloat = 0.0 - var firstY:CGFloat = 0.0 - - // timer - var controlVisibilityTimer:NSTimer! - - // delegate - weak public var delegate: SKPhotoBrowserDelegate? - + // MARK - Initializer required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setup() @@ -120,8 +121,6 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate{ NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleSKPhotoLoadingDidEndNotification:", name: SKPHOTO_LOADING_DID_END_NOTIFICATION, object: nil) } - - // MARK: - override public override func viewDidLoad() { super.viewDidLoad() diff --git a/SKPhotoBrowser/SKZoomingScrollView.swift b/SKPhotoBrowser/SKZoomingScrollView.swift index 8c9b634..3d6c265 100644 --- a/SKPhotoBrowser/SKZoomingScrollView.swift +++ b/SKPhotoBrowser/SKZoomingScrollView.swift @@ -10,7 +10,7 @@ import UIKit public class SKZoomingScrollView:UIScrollView, UIScrollViewDelegate, SKDetectingViewDelegate, SKDetectingImageViewDelegate{ - weak var photoBrowser:SKPhotoBrowser! + var captionView:SKCaptionView! var photo:SKPhoto!{ didSet{ photoImageView.image = nil @@ -18,10 +18,10 @@ public class SKZoomingScrollView:UIScrollView, UIScrollViewDelegate, SKDetecting } } - var captionView:SKCaptionView! - var tapView:SKDetectingView! - var photoImageView:SKDetectingImageView! - var indicatorView: SKIndicatorView! + private weak var photoBrowser:SKPhotoBrowser! + private var tapView:SKDetectingView! + private var photoImageView:SKDetectingImageView! + private var indicatorView: SKIndicatorView! required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) @@ -51,7 +51,8 @@ public class SKZoomingScrollView:UIScrollView, UIScrollViewDelegate, SKDetecting // image photoImageView = SKDetectingImageView(frame: frame) photoImageView.delegate = self - photoImageView.backgroundColor = UIColor.clearColor() + photoImageView.contentMode = .Center + photoImageView.backgroundColor = .clearColor() addSubview(photoImageView) // indicator @@ -59,20 +60,21 @@ public class SKZoomingScrollView:UIScrollView, UIScrollViewDelegate, SKDetecting addSubview(indicatorView) // self - backgroundColor = UIColor.clearColor() + backgroundColor = .clearColor() delegate = self showsHorizontalScrollIndicator = false showsVerticalScrollIndicator = false decelerationRate = UIScrollViewDecelerationRateFast - autoresizingMask = [.FlexibleHeight, .FlexibleWidth] + autoresizingMask = [.FlexibleWidth, .FlexibleTopMargin, .FlexibleBottomMargin, .FlexibleRightMargin, .FlexibleLeftMargin] } // MARK: - override public override func layoutSubviews() { - super.layoutSubviews() tapView.frame = bounds + super.layoutSubviews() + let boundsSize = bounds.size var frameToCenter = photoImageView.frame @@ -101,7 +103,7 @@ public class SKZoomingScrollView:UIScrollView, UIScrollViewDelegate, SKDetecting minimumZoomScale = 1 zoomScale = 1 - if photoImageView == nil { + guard let photoImageView = photoImageView else { return } @@ -110,8 +112,8 @@ public class SKZoomingScrollView:UIScrollView, UIScrollViewDelegate, SKDetecting let xScale = boundsSize.width / imageSize.width let yScale = boundsSize.height / imageSize.height - var maxScale:CGFloat = 4.0 let minScale:CGFloat = min(xScale, yScale) + var maxScale:CGFloat = 4.0 maximumZoomScale = maxScale minimumZoomScale = minScale