Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
mattga committed Dec 13, 2015
1 parent de23301 commit 24e579a
Show file tree
Hide file tree
Showing 7 changed files with 543 additions and 2 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Xcode
#
build/
Demo/build/
*.pbxuser
!default.pbxuser
*.mode1v3
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 mattga
Copyright (c) 2015 Matthew Gardner

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
137 changes: 137 additions & 0 deletions MGCollapsibleHeader.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#
# Be sure to run `pod spec lint MGCollapsibleHeader.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#
@version = "1.0.1"

Pod::Spec.new do |s|

# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# These will help people to find your library, and whilst it
# can feel like a chore to fill in it's definitely to your advantage. The
# summary should be tweet-length, and the description more in depth.
#

s.name = "MGCollapsibleHeader"
s.version = @version
s.summary = "A short description of MGCollapsibleHeader."

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
DESC

s.homepage = "https://github.com/mattga/MGCollapsibleHeader"
s.screenshots = "https://github.com/mattga/MGCollapsibleHeader/raw/master/Screenshots/mgcollapsibleheader_demo.gif"


# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Licensing your code is important. See http://choosealicense.com for more info.
# CocoaPods will detect a license file if there is a named LICENSE*
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
#

s.license = { :type => "MIT", :file => "LICENSE" }


# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the authors of the library, with email addresses. Email addresses
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
# accepts just a name if you'd rather not provide an email address.
#
# Specify a social_media_url where others can refer to, for example a twitter
# profile URL.
#

s.author = { "Matthew Gardner" => "[email protected]" }
# Or just: s.author = "Matthew Gardner"
# s.authors = { "Matthew Gardner" => "[email protected]" }
# s.social_media_url = "http://twitter.com/Matthew Gardner"

# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If this Pod runs only on iOS or OS X, then specify the platform and
# the deployment target. You can optionally include the target after the platform.
#

s.platform = :ios
# s.platform = :ios, "7.0"

# When using multiple platforms
# s.ios.deployment_target = "5.0"
# s.osx.deployment_target = "10.7"
# s.watchos.deployment_target = "2.0"
# s.tvos.deployment_target = "9.0"


# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#

s.source = { :git => "https://github.com/mattga/MGCollapsibleHeader.git", :tag => "v#{s.version}" }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# CocoaPods is smart about how it includes source code. For source files
# giving a folder will include any swift, h, m, mm, c & cpp files.
# For header files it will include any header in the folder.
# Not including the public_header_files will make all headers public.
#

s.header_mappings_dir = "Source"
s.source_files = "Source/**/*.{h,m}"

# s.public_header_files = "Classes/**/*.h"


# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# A list of resources included with the Pod. These are copied into the
# target bundle with a build phase script. Anything else will be cleaned.
# You can preserve files from being cleaned, please don't preserve
# non-essential files like tests, examples and documentation.
#

# s.resource = "icon.png"
# s.resources = "Resources/*.png"

# s.preserve_paths = "FilesToSave", "MoreFilesToSave"


# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Link your library with frameworks, or libraries. Libraries do not include
# the lib prefix of their name.
#

# s.framework = "SomeFramework"
# s.frameworks = "SomeFramework", "AnotherFramework"

# s.library = "iconv"
# s.libraries = "iconv", "xml2"


# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If your library depends on compiler flags you can set them in the xcconfig hash
# where they will only apply to your library. If you depend on other Podspecs
# you can include multiple dependencies to ensure it works.

# s.requires_arc = true

# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
# s.dependency "JSONKit", "~> 1.4"

end
120 changes: 120 additions & 0 deletions MGCollapsibleHeader/MGCollapsibleHeaderView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//
// The MIT License (MIT)
//
// Copyright (c) 2015 Matthew Gardner
//
// 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/UIKit.h>

@protocol MGCollapsibleHeaderDelegate <NSObject>

- (void)headerDidCollapse;
- (void)headerDidFinishCollapsing;
- (void)headerDidExpand;
- (void)headerDidFinishExpanding;

@end

// TODO: Transform Functions
typedef enum : NSUInteger {
MGTransformCurveLinear = 0,
MGTransformCurveEaseIn,
MGTransformCurveEaseOut,
MGTransformCurveEaseInOut,
} MGTransformCurve;

/*!
* @typedef MGAttribute
* @brief Enumeration of attributes that can be transformed when scrolling.
* @constant MGAttributeX x-value of a view's origin.
* @constant MGAttributeY y-value of a view's origin.
* @constant MGAttributeWidth Width of a view.
* @constant MGAttributeHeight Height of a view.
* @constant MGAttributeAlpha Apha value of a view.
* @constant MGAttributeCornerRadius Corner radius of a view.
* @constant MGAttributeShadowRadius Shadow radius of a view.
* @constant MGAttributeCornerRadius Shadow opacity of a view.
*/
typedef enum : NSUInteger {
MGAttributeX = 1,
MGAttributeY,
MGAttributeWidth,
MGAttributeHeight,
MGAttributeAlpha,
MGAttributeCornerRadius,
MGAttributeShadowRadius,
MGAttributeShadowOpacity
} MGAttribute;

/*!
* @brief Defines an attribute to be transformed when scrolling.
*/
@interface MGTransformAttribute : NSObject

@property (nonatomic) MGAttribute attribute;
@property (nonatomic) MGTransformCurve curve;
@property (nonatomic) CGFloat value, origValue, dValue;

+ (instancetype)attribute:(MGAttribute)attr value:(CGFloat)val;

@end

/*!
* @brief Subclass of UIView that manages collapsing and expanding.
*/
@interface MGCollapsibleHeaderView : UIView {
NSMutableArray *transfViews, *fadeViews;
NSMutableDictionary *constrs, *constrVals, *transfAttrs, *alphaRatios;
CGFloat lastOffset;
CGFloat header_ht, scroll_ht, offset_max;
NSLayoutConstraint *headerTop;
}

@property (nonatomic) CGFloat minimumHeaderHeight;

@property (strong, nonatomic) NSLayoutConstraint *scrollViewTop;

/*!
* @discussion Adds a subview of the header that transforms as the user scrolls.
* @param view The view to transform.
* @param attrs A dictionary of attributes that describe the view in it's condensed form.
Keys must be a MGAttribute; Values must be a double.
* @return Boolean identifying if the transform was successfully added.
*/
- (BOOL)addTransformingSubview:(UIView *)view attributes:(NSArray *)attrs;

/*!
* @discussion Adds a subview of the header that fades as the user scrolls.
* @param view The view to fade away.
* @param ratio The ratio of collapsing at which the subview will finish fading away.
* @return Boolean identifying if the fading subview was successfully added.
*/
- (BOOL)addFadingSubview:(UIView *)view fadeBy:(CGFloat)ratio;

/*!
* @discussion Tells the header to collapse with some offset. This should be called from
a scrollViewDidScroll call.
* @param offset The content offset of the scroll view.
*/
- (void)collapseToOffset:(CGPoint)offset;

@end
Loading

0 comments on commit 24e579a

Please sign in to comment.