├── AutoResizeCellDemo
├── AutoResizeCellDemo
│ ├── images
│ │ ├── avatar.jpeg
│ │ ├── avatar@2x.jpeg
│ │ └── avatar@3x.jpeg
│ ├── vendor
│ │ ├── SVProgressHUD
│ │ │ ├── SVProgressHUD.bundle
│ │ │ │ ├── error@2x.png
│ │ │ │ ├── success@2x.png
│ │ │ │ └── angle-mask@2x.png
│ │ │ ├── SVProgressHUD.h
│ │ │ └── SVProgressHUD.m
│ │ └── Masonry
│ │ │ ├── MASLayoutConstraint.m
│ │ │ ├── NSLayoutConstraint+MASDebugAdditions.h
│ │ │ ├── MASLayoutConstraint.h
│ │ │ ├── MASCompositeConstraint.h
│ │ │ ├── Masonry.h
│ │ │ ├── category
│ │ │ ├── UIView+AverageRange.h
│ │ │ └── UIView+AverageRange.m
│ │ │ ├── MASViewAttribute.h
│ │ │ ├── MASViewAttribute.m
│ │ │ ├── NSArray+MASShorthandAdditions.h
│ │ │ ├── MASViewConstraint.h
│ │ │ ├── NSArray+MASAdditions.m
│ │ │ ├── NSArray+MASAdditions.h
│ │ │ ├── MASConstraint+Private.h
│ │ │ ├── View+MASShorthandAdditions.h
│ │ │ ├── View+MASAdditions.h
│ │ │ ├── MASConstraintMaker.h
│ │ │ ├── View+MASAdditions.m
│ │ │ ├── MASCompositeConstraint.m
│ │ │ ├── NSLayoutConstraint+MASDebugAdditions.m
│ │ │ ├── MASUtilities.h
│ │ │ ├── MASConstraint.h
│ │ │ ├── MASConstraint.m
│ │ │ ├── MASConstraintMaker.m
│ │ │ └── MASViewConstraint.m
│ ├── ViewController.h
│ ├── controllers
│ │ ├── AutoResizeCellController.h
│ │ ├── AutoResizeTableController.h
│ │ ├── AutoResizeTableController.m
│ │ └── AutoResizeCellController.m
│ ├── AppDelegate.h
│ ├── main.m
│ ├── views
│ │ ├── AutoResizeCell.h
│ │ ├── SecondResizeCell.h
│ │ ├── AutoResizeCell.m
│ │ └── SecondResizeCell.m
│ ├── Images.xcassets
│ │ ├── LaunchImage.launchimage
│ │ │ └── Contents.json
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── Info.plist
│ ├── Base.lproj
│ │ ├── Main.storyboard
│ │ └── LaunchScreen.xib
│ ├── ViewController.m
│ └── AppDelegate.m
├── AutoResizeCellDemo.xcodeproj
│ ├── project.xcworkspace
│ │ └── contents.xcworkspacedata
│ └── project.pbxproj
└── AutoResizeCellDemoTests
│ ├── Info.plist
│ └── AutoResizeCellDemoTests.m
├── .gitignore
├── LICENSE
└── README.md
/AutoResizeCellDemo/AutoResizeCellDemo/images/avatar.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aevit/SCAutoResizeCellDemo/HEAD/AutoResizeCellDemo/AutoResizeCellDemo/images/avatar.jpeg
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/images/avatar@2x.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aevit/SCAutoResizeCellDemo/HEAD/AutoResizeCellDemo/AutoResizeCellDemo/images/avatar@2x.jpeg
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/images/avatar@3x.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aevit/SCAutoResizeCellDemo/HEAD/AutoResizeCellDemo/AutoResizeCellDemo/images/avatar@3x.jpeg
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/SVProgressHUD/SVProgressHUD.bundle/error@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aevit/SCAutoResizeCellDemo/HEAD/AutoResizeCellDemo/AutoResizeCellDemo/vendor/SVProgressHUD/SVProgressHUD.bundle/error@2x.png
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/SVProgressHUD/SVProgressHUD.bundle/success@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aevit/SCAutoResizeCellDemo/HEAD/AutoResizeCellDemo/AutoResizeCellDemo/vendor/SVProgressHUD/SVProgressHUD.bundle/success@2x.png
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/SVProgressHUD/SVProgressHUD.bundle/angle-mask@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aevit/SCAutoResizeCellDemo/HEAD/AutoResizeCellDemo/AutoResizeCellDemo/vendor/SVProgressHUD/SVProgressHUD.bundle/angle-mask@2x.png
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // AutoResizeCellDemo
4 | //
5 | // Created by Aevitx on 14/12/3.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASLayoutConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASLayoutConstraint.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "MASLayoutConstraint.h"
10 |
11 | @implementation MASLayoutConstraint
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/controllers/AutoResizeCellController.h:
--------------------------------------------------------------------------------
1 | //
2 | // AutoResizeCellController.h
3 | // AutoResizeCellDemo
4 | //
5 | // Created by Aevitx on 14/12/3.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AutoResizeCellController : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/controllers/AutoResizeTableController.h:
--------------------------------------------------------------------------------
1 | //
2 | // AutoResizeTableController.h
3 | // AutoResizeCellDemo
4 | //
5 | // Created by Aevitx on 14/12/3.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AutoResizeTableController : UITableViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // AutoResizeCellDemo
4 | //
5 | // Created by Aevitx on 14/12/3.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // AutoResizeCellDemo
4 | //
5 | // Created by Aevitx on 14/12/3.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/NSLayoutConstraint+MASDebugAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSLayoutConstraint+MASDebugAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * makes debug and log output of NSLayoutConstraints more readable
13 | */
14 | @interface NSLayoutConstraint (MASDebugAdditions)
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/views/AutoResizeCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // AutoResizeCell.h
3 | // AutoResizeCellDemo
4 | //
5 | // Created by Aevitx on 14/12/3.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AutoResizeCell : UITableViewCell
12 |
13 | @property (strong, nonatomic) UILabel *titleLabel;
14 | @property (strong, nonatomic) UILabel *bodyLabel;
15 |
16 | - (void)initModel:(id)model;
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/views/SecondResizeCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // SecondResizeCell.h
3 | // AutoResizeCellDemo
4 | //
5 | // Created by Aevitx on 14/12/11.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface SecondResizeCell : UITableViewCell
12 |
13 | @property (strong, nonatomic) UILabel *titleLabel;
14 | @property (strong, nonatomic) UILabel *bodyLabel;
15 | @property (strong, nonatomic) UIImageView *avatarImgView;
16 |
17 | - (void)initModel:(id)model;
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/Images.xcassets/LaunchImage.launchimage/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "orientation" : "portrait",
5 | "idiom" : "iphone",
6 | "minimum-system-version" : "7.0",
7 | "scale" : "2x"
8 | },
9 | {
10 | "orientation" : "portrait",
11 | "idiom" : "iphone",
12 | "minimum-system-version" : "7.0",
13 | "subtype" : "retina4",
14 | "scale" : "2x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | build/
4 | *.pbxuser
5 | !default.pbxuser
6 | *.mode1v3
7 | !default.mode1v3
8 | *.mode2v3
9 | !default.mode2v3
10 | *.perspectivev3
11 | !default.perspectivev3
12 | xcuserdata
13 | *.xccheckout
14 | *.moved-aside
15 | DerivedData
16 | *.hmap
17 | *.ipa
18 | *.xcuserstate
19 |
20 | # CocoaPods
21 | #
22 | # We recommend against adding the Pods directory to your .gitignore. However
23 | # you should judge for yourself, the pros and cons are mentioned at:
24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
25 | #
26 | # Pods/
27 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASLayoutConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASLayoutConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * When you are debugging or printing the constraints attached to a view this subclass
13 | * makes it easier to identify which constraints have been created via Masonry
14 | */
15 | @interface MASLayoutConstraint : NSLayoutConstraint
16 |
17 | /**
18 | * a key to associate with this constraint
19 | */
20 | @property (nonatomic, strong) id mas_key;
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASCompositeConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASCompositeConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraint.h"
10 | #import "MASUtilities.h"
11 |
12 | /**
13 | * A group of MASConstraint objects
14 | */
15 | @interface MASCompositeConstraint : MASConstraint
16 |
17 | /**
18 | * Creates a composite with a predefined array of children
19 | *
20 | * @param children child MASConstraints
21 | *
22 | * @return a composite constraint
23 | */
24 | - (id)initWithChildren:(NSArray *)children;
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/Masonry.h:
--------------------------------------------------------------------------------
1 | //
2 | // Masonry.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 | #import "View+MASAdditions.h"
11 | #import "View+MASShorthandAdditions.h"
12 | #import "NSArray+MASAdditions.h"
13 | #import "NSArray+MASShorthandAdditions.h"
14 | #import "MASConstraint.h"
15 | #import "MASCompositeConstraint.h"
16 | #import "MASViewAttribute.h"
17 | #import "MASViewConstraint.h"
18 | #import "MASConstraintMaker.h"
19 | #import "MASLayoutConstraint.h"
20 | #import "NSLayoutConstraint+MASDebugAdditions.h"
21 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/category/UIView+AverageRange.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+AverageRange.h
3 | // WeTime
4 | //
5 | // Created by Aevitx on 14/11/29.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 | // from http://adad184.com/2014/09/28/use-masonry-to-quick-solve-autolayout/
9 |
10 | #import
11 |
12 | @interface UIView (AverageRange)
13 |
14 | /**
15 | * 水平方向,平均分布views
16 | *
17 | * @param views 所有子views
18 | */
19 | - (void)distributeSpacingHorizontallyWith:(NSArray*)views;
20 |
21 |
22 | /**
23 | * 竖直方向,平均分布views
24 | *
25 | * @param views 所有子views
26 | */
27 | - (void)distributeSpacingVerticallyWith:(NSArray*)views;
28 |
29 | @end
30 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | }
33 | ],
34 | "info" : {
35 | "version" : 1,
36 | "author" : "xcode"
37 | }
38 | }
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemoTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | tk.aevit.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemoTests/AutoResizeCellDemoTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // AutoResizeCellDemoTests.m
3 | // AutoResizeCellDemoTests
4 | //
5 | // Created by Aevitx on 14/12/3.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface AutoResizeCellDemoTests : XCTestCase
13 |
14 | @end
15 |
16 | @implementation AutoResizeCellDemoTests
17 |
18 | - (void)setUp {
19 | [super setUp];
20 | // Put setup code here. This method is called before the invocation of each test method in the class.
21 | }
22 |
23 | - (void)tearDown {
24 | // Put teardown code here. This method is called after the invocation of each test method in the class.
25 | [super tearDown];
26 | }
27 |
28 | - (void)testExample {
29 | // This is an example of a functional test case.
30 | XCTAssert(YES, @"Pass");
31 | }
32 |
33 | - (void)testPerformanceExample {
34 | // This is an example of a performance test case.
35 | [self measureBlock:^{
36 | // Put the code you want to measure the time of here.
37 | }];
38 | }
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Aevit
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASViewAttribute.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASAttribute.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * An immutable tuple which stores the view and the related NSLayoutAttribute.
13 | * Describes part of either the left or right hand side of a constraint equation
14 | */
15 | @interface MASViewAttribute : NSObject
16 |
17 | /**
18 | * The view which the reciever relates to
19 | */
20 | @property (nonatomic, weak, readonly) MAS_VIEW *view;
21 |
22 | /**
23 | * The attribute which the reciever relates to
24 | */
25 | @property (nonatomic, assign, readonly) NSLayoutAttribute layoutAttribute;
26 |
27 | /**
28 | * The designated initializer.
29 | */
30 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute;
31 |
32 | /**
33 | * Determine whether the layoutAttribute is a size attribute
34 | *
35 | * @return YES if layoutAttribute is equal to NSLayoutAttributeWidth or NSLayoutAttributeHeight
36 | */
37 | - (BOOL)isSizeAttribute;
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASViewAttribute.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASAttribute.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASViewAttribute.h"
10 |
11 | @implementation MASViewAttribute
12 |
13 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute {
14 | self = [super init];
15 | if (!self) return nil;
16 |
17 | _view = view;
18 | _layoutAttribute = layoutAttribute;
19 |
20 | return self;
21 | }
22 |
23 | - (BOOL)isSizeAttribute {
24 | return self.layoutAttribute == NSLayoutAttributeWidth
25 | || self.layoutAttribute == NSLayoutAttributeHeight;
26 | }
27 |
28 | - (BOOL)isEqual:(MASViewAttribute *)viewAttribute {
29 | if ([viewAttribute isKindOfClass:self.class]) {
30 | return self.view == viewAttribute.view
31 | && self.layoutAttribute == viewAttribute.layoutAttribute;
32 | }
33 | return [super isEqual:viewAttribute];
34 | }
35 |
36 | - (NSUInteger)hash {
37 | return MAS_NSUINTROTATE([self.view hash], MAS_NSUINT_BIT / 2) ^ self.layoutAttribute;
38 | }
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/NSArray+MASShorthandAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+MASShorthandAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 22/07/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "NSArray+MASAdditions.h"
10 |
11 | #ifdef MAS_SHORTHAND
12 |
13 | /**
14 | * Shorthand array additions without the 'mas_' prefixes,
15 | * only enabled if MAS_SHORTHAND is defined
16 | */
17 | @interface NSArray (MASShorthandAdditions)
18 |
19 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
20 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
21 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
22 |
23 | @end
24 |
25 | @implementation NSArray (MASShorthandAdditions)
26 |
27 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block {
28 | return [self mas_makeConstraints:block];
29 | }
30 |
31 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block {
32 | return [self mas_updateConstraints:block];
33 | }
34 |
35 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block {
36 | return [self mas_remakeConstraints:block];
37 | }
38 |
39 | @end
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | tk.aevit.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASViewConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASViewAttribute.h"
10 | #import "MASConstraint.h"
11 | #import "MASLayoutConstraint.h"
12 | #import "MASUtilities.h"
13 |
14 | /**
15 | * A single constraint.
16 | * Contains the attributes neccessary for creating a NSLayoutConstraint and adding it to the appropriate view
17 | */
18 | @interface MASViewConstraint : MASConstraint
19 |
20 | /**
21 | * First item/view and first attribute of the NSLayoutConstraint
22 | */
23 | @property (nonatomic, strong, readonly) MASViewAttribute *firstViewAttribute;
24 |
25 | /**
26 | * Second item/view and second attribute of the NSLayoutConstraint
27 | */
28 | @property (nonatomic, strong, readonly) MASViewAttribute *secondViewAttribute;
29 |
30 | /**
31 | * initialises the MASViewConstraint with the first part of the equation
32 | *
33 | * @param firstViewAttribute view.mas_left, view.mas_width etc.
34 | *
35 | * @return a new view constraint
36 | */
37 | - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute;
38 |
39 | /**
40 | * Returns all MASViewConstraints installed with this view as a first item.
41 | *
42 | * @param view A view to retrieve constraints for.
43 | *
44 | * @return An array of MASViewConstraints.
45 | */
46 | + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view;
47 |
48 | @end
49 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/NSArray+MASAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+MASAdditions.m
3 | //
4 | //
5 | // Created by Daniel Hammond on 11/26/13.
6 | //
7 | //
8 |
9 | #import "NSArray+MASAdditions.h"
10 | #import "View+MASAdditions.h"
11 |
12 | @implementation NSArray (MASAdditions)
13 |
14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block {
15 | NSMutableArray *constraints = [NSMutableArray array];
16 | for (MAS_VIEW *view in self) {
17 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views");
18 | [constraints addObjectsFromArray:[view mas_makeConstraints:block]];
19 | }
20 | return constraints;
21 | }
22 |
23 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block {
24 | NSMutableArray *constraints = [NSMutableArray array];
25 | for (MAS_VIEW *view in self) {
26 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views");
27 | [constraints addObjectsFromArray:[view mas_updateConstraints:block]];
28 | }
29 | return constraints;
30 | }
31 |
32 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block {
33 | NSMutableArray *constraints = [NSMutableArray array];
34 | for (MAS_VIEW *view in self) {
35 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views");
36 | [constraints addObjectsFromArray:[view mas_remakeConstraints:block]];
37 | }
38 | return constraints;
39 | }
40 |
41 | @end
42 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/NSArray+MASAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+MASAdditions.h
3 | //
4 | //
5 | // Created by Daniel Hammond on 11/26/13.
6 | //
7 | //
8 |
9 | #import "MASUtilities.h"
10 | #import "MASConstraintMaker.h"
11 | #import "MASViewAttribute.h"
12 |
13 | @interface NSArray (MASAdditions)
14 |
15 | /**
16 | * Creates a MASConstraintMaker with each view in the callee.
17 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing on each view
18 | *
19 | * @param block scope within which you can build up the constraints which you wish to apply to each view.
20 | *
21 | * @return Array of created MASConstraints
22 | */
23 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block;
24 |
25 | /**
26 | * Creates a MASConstraintMaker with each view in the callee.
27 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view.
28 | * If an existing constraint exists then it will be updated instead.
29 | *
30 | * @param block scope within which you can build up the constraints which you wish to apply to each view.
31 | *
32 | * @return Array of created/updated MASConstraints
33 | */
34 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block;
35 |
36 | /**
37 | * Creates a MASConstraintMaker with each view in the callee.
38 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view.
39 | * All constraints previously installed for the views will be removed.
40 | *
41 | * @param block scope within which you can build up the constraints which you wish to apply to each view.
42 | *
43 | * @return Array of created/updated MASConstraints
44 | */
45 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block;
46 |
47 | @end
48 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // AutoResizeCellDemo
4 | //
5 | // Created by Aevitx on 14/12/3.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 | #import "AutoResizeCellController.h"
11 | #import "Masonry.h"
12 |
13 | @interface ViewController ()
14 |
15 | @end
16 |
17 | @implementation ViewController
18 |
19 | - (void)viewDidLoad {
20 | [super viewDidLoad];
21 | // Do any additional setup after loading the view, typically from a nib.
22 | UIButton *aBtn = [UIButton buttonWithType:UIButtonTypeCustom];
23 | aBtn.frame = (CGRect){.origin = CGPointZero, .size = CGSizeMake(80, 80)};
24 | aBtn.center = self.view.center;
25 | aBtn.layer.borderColor = [UIColor darkGrayColor].CGColor;
26 | aBtn.layer.borderWidth = 1.;
27 | aBtn.layer.cornerRadius = 40.;
28 | [aBtn setTitle:@"show" forState:UIControlStateNormal];
29 | [aBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
30 | [aBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
31 | [aBtn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
32 | [self.view addSubview:aBtn];
33 |
34 | [aBtn mas_makeConstraints:^(MASConstraintMaker *make) {
35 | make.center.mas_equalTo(self.view);
36 | make.size.mas_equalTo(CGSizeMake(80, 80));
37 | }];
38 | }
39 |
40 | - (void)didReceiveMemoryWarning {
41 | [super didReceiveMemoryWarning];
42 | // Dispose of any resources that can be recreated.
43 | }
44 |
45 | - (void)btnPressed:(id)sender {
46 | AutoResizeCellController *con = [[AutoResizeCellController alloc] init];
47 | UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:con];
48 | [self presentViewController:nav animated:YES completion:^{
49 | ;
50 | }];
51 | }
52 |
53 | @end
54 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASConstraint+Private.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint+Private.h
3 | // Masonry
4 | //
5 | // Created by Nick Tymchenko on 29/04/14.
6 | // Copyright (c) 2014 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraint.h"
10 |
11 | @protocol MASConstraintDelegate;
12 |
13 |
14 | @interface MASConstraint ()
15 |
16 | /**
17 | * Whether or not to check for an existing constraint instead of adding constraint
18 | */
19 | @property (nonatomic, assign) BOOL updateExisting;
20 |
21 | /**
22 | * Usually MASConstraintMaker but could be a parent MASConstraint
23 | */
24 | @property (nonatomic, weak) id delegate;
25 |
26 | /**
27 | * Based on a provided value type, is equal to calling:
28 | * NSNumber - setOffset:
29 | * NSValue with CGPoint - setPointOffset:
30 | * NSValue with CGSize - setSizeOffset:
31 | * NSValue with MASEdgeInsets - setInsets:
32 | */
33 | - (void)setLayoutConstantWithValue:(NSValue *)value;
34 |
35 | @end
36 |
37 |
38 | @interface MASConstraint (Abstract)
39 |
40 | /**
41 | * Sets the constraint relation to given NSLayoutRelation
42 | * returns a block which accepts one of the following:
43 | * MASViewAttribute, UIView, NSValue, NSArray
44 | * see readme for more details.
45 | */
46 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation;
47 |
48 | /**
49 | * Override to set a custom chaining behaviour
50 | */
51 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute;
52 |
53 | @end
54 |
55 |
56 | @protocol MASConstraintDelegate
57 |
58 | /**
59 | * Notifies the delegate when the constraint needs to be replaced with another constraint. For example
60 | * A MASViewConstraint may turn into a MASCompositeConstraint when an array is passed to one of the equality blocks
61 | */
62 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint;
63 |
64 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute;
65 |
66 | @end
67 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // AutoResizeCellDemo
4 | //
5 | // Created by Aevitx on 14/12/3.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 | //#import "DCIntrospect.h"
11 |
12 | @interface AppDelegate ()
13 |
14 | @end
15 |
16 | @implementation AppDelegate
17 |
18 |
19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
20 | // Override point for customization after application launch.
21 | // DCIntrospect
22 | //#if TARGET_IPHONE_SIMULATOR
23 | // [[DCIntrospect sharedIntrospector] start];
24 | //#endif
25 | return YES;
26 | }
27 |
28 | - (void)applicationWillResignActive:(UIApplication *)application {
29 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
30 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
31 | }
32 |
33 | - (void)applicationDidEnterBackground:(UIApplication *)application {
34 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
35 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
36 | }
37 |
38 | - (void)applicationWillEnterForeground:(UIApplication *)application {
39 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
40 | }
41 |
42 | - (void)applicationDidBecomeActive:(UIApplication *)application {
43 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
44 | }
45 |
46 | - (void)applicationWillTerminate:(UIApplication *)application {
47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
48 | }
49 |
50 | @end
51 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/View+MASShorthandAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+MASShorthandAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 22/07/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "View+MASAdditions.h"
10 |
11 | #ifdef MAS_SHORTHAND
12 |
13 | /**
14 | * Shorthand view additions without the 'mas_' prefixes,
15 | * only enabled if MAS_SHORTHAND is defined
16 | */
17 | @interface MAS_VIEW (MASShorthandAdditions)
18 |
19 | @property (nonatomic, strong, readonly) MASViewAttribute *left;
20 | @property (nonatomic, strong, readonly) MASViewAttribute *top;
21 | @property (nonatomic, strong, readonly) MASViewAttribute *right;
22 | @property (nonatomic, strong, readonly) MASViewAttribute *bottom;
23 | @property (nonatomic, strong, readonly) MASViewAttribute *leading;
24 | @property (nonatomic, strong, readonly) MASViewAttribute *trailing;
25 | @property (nonatomic, strong, readonly) MASViewAttribute *width;
26 | @property (nonatomic, strong, readonly) MASViewAttribute *height;
27 | @property (nonatomic, strong, readonly) MASViewAttribute *centerX;
28 | @property (nonatomic, strong, readonly) MASViewAttribute *centerY;
29 | @property (nonatomic, strong, readonly) MASViewAttribute *baseline;
30 | @property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr);
31 |
32 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
33 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
34 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
35 |
36 | @end
37 |
38 | #define MAS_ATTR_FORWARD(attr) \
39 | - (MASViewAttribute *)attr { \
40 | return [self mas_##attr]; \
41 | }
42 |
43 | @implementation MAS_VIEW (MASShorthandAdditions)
44 |
45 | MAS_ATTR_FORWARD(top);
46 | MAS_ATTR_FORWARD(left);
47 | MAS_ATTR_FORWARD(bottom);
48 | MAS_ATTR_FORWARD(right);
49 | MAS_ATTR_FORWARD(leading);
50 | MAS_ATTR_FORWARD(trailing);
51 | MAS_ATTR_FORWARD(width);
52 | MAS_ATTR_FORWARD(height);
53 | MAS_ATTR_FORWARD(centerX);
54 | MAS_ATTR_FORWARD(centerY);
55 | MAS_ATTR_FORWARD(baseline);
56 |
57 | - (MASViewAttribute *(^)(NSLayoutAttribute))attribute {
58 | return [self mas_attribute];
59 | }
60 |
61 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block {
62 | return [self mas_makeConstraints:block];
63 | }
64 |
65 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block {
66 | return [self mas_updateConstraints:block];
67 | }
68 |
69 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block {
70 | return [self mas_remakeConstraints:block];
71 | }
72 |
73 | @end
74 |
75 | #endif
76 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/SVProgressHUD/SVProgressHUD.h:
--------------------------------------------------------------------------------
1 | //
2 | // SVProgressHUD.h
3 | //
4 | // Created by Sam Vermette on 27.03.11.
5 | // Copyright 2011 Sam Vermette. All rights reserved.
6 | //
7 | // https://github.com/samvermette/SVProgressHUD
8 | //
9 |
10 | #import
11 | #import
12 |
13 | extern NSString * const SVProgressHUDDidReceiveTouchEventNotification;
14 | extern NSString * const SVProgressHUDWillDisappearNotification;
15 | extern NSString * const SVProgressHUDDidDisappearNotification;
16 | extern NSString * const SVProgressHUDWillAppearNotification;
17 | extern NSString * const SVProgressHUDDidAppearNotification;
18 |
19 | extern NSString * const SVProgressHUDStatusUserInfoKey;
20 |
21 | typedef NS_ENUM(NSUInteger, SVProgressHUDMaskType) {
22 | SVProgressHUDMaskTypeNone = 1, // allow user interactions while HUD is displayed
23 | SVProgressHUDMaskTypeClear, // don't allow
24 | SVProgressHUDMaskTypeBlack, // don't allow and dim the UI in the back of the HUD
25 | SVProgressHUDMaskTypeGradient // don't allow and dim the UI with a a-la-alert-view bg gradient
26 | };
27 |
28 | @interface SVProgressHUD : UIView
29 |
30 | #pragma mark - Customization
31 |
32 | + (void)setBackgroundColor:(UIColor*)color; // default is [UIColor whiteColor]
33 | + (void)setForegroundColor:(UIColor*)color; // default is [UIColor blackColor]
34 | + (void)setRingThickness:(CGFloat)width; // default is 4 pt
35 | + (void)setFont:(UIFont*)font; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
36 | + (void)setSuccessImage:(UIImage*)image; // default is bundled success image from Glyphish
37 | + (void)setErrorImage:(UIImage*)image; // default is bundled error image from Glyphish
38 |
39 | #pragma mark - Show Methods
40 |
41 | + (void)show;
42 | + (void)showWithMaskType:(SVProgressHUDMaskType)maskType;
43 | + (void)showWithStatus:(NSString*)status;
44 | + (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
45 |
46 | + (void)showProgress:(float)progress;
47 | + (void)showProgress:(float)progress status:(NSString*)status;
48 | + (void)showProgress:(float)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
49 |
50 | + (void)setStatus:(NSString*)string; // change the HUD loading status while it's showing
51 |
52 | // stops the activity indicator, shows a glyph + status, and dismisses HUD 1s later
53 | + (void)showSuccessWithStatus:(NSString*)string;
54 | + (void)showErrorWithStatus:(NSString *)string;
55 | + (void)showImage:(UIImage*)image status:(NSString*)status; // use 28x28 white pngs
56 |
57 | + (void)setOffsetFromCenter:(UIOffset)offset;
58 | + (void)resetOffsetFromCenter;
59 |
60 | + (void)popActivity;
61 | + (void)dismiss;
62 |
63 | + (BOOL)isVisible;
64 |
65 | @end
66 |
67 |
68 | @interface SVIndefiniteAnimatedView : UIView
69 |
70 | @property (nonatomic, assign) CGFloat strokeThickness;
71 | @property (nonatomic, assign) CGFloat radius;
72 | @property (nonatomic, strong) UIColor *strokeColor;
73 |
74 | @end
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/View+MASAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+MASAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 | #import "MASConstraintMaker.h"
11 | #import "MASViewAttribute.h"
12 |
13 | /**
14 | * Provides constraint maker block
15 | * and convience methods for creating MASViewAttribute which are view + NSLayoutAttribute pairs
16 | */
17 | @interface MAS_VIEW (MASAdditions)
18 |
19 | /**
20 | * following properties return a new MASViewAttribute with current view and appropriate NSLayoutAttribute
21 | */
22 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_left;
23 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_top;
24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_right;
25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom;
26 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leading;
27 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing;
28 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_width;
29 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_height;
30 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX;
31 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY;
32 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline;
33 | @property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr);
34 |
35 | /**
36 | * a key to associate with this view
37 | */
38 | @property (nonatomic, strong) id mas_key;
39 |
40 | /**
41 | * Finds the closest common superview between this view and another view
42 | *
43 | * @param view other view
44 | *
45 | * @return returns nil if common superview could not be found
46 | */
47 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view;
48 |
49 | /**
50 | * Creates a MASConstraintMaker with the callee view.
51 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing
52 | *
53 | * @param block scope within which you can build up the constraints which you wish to apply to the view.
54 | *
55 | * @return Array of created MASConstraints
56 | */
57 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block;
58 |
59 | /**
60 | * Creates a MASConstraintMaker with the callee view.
61 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
62 | * If an existing constraint exists then it will be updated instead.
63 | *
64 | * @param block scope within which you can build up the constraints which you wish to apply to the view.
65 | *
66 | * @return Array of created/updated MASConstraints
67 | */
68 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block;
69 |
70 | /**
71 | * Creates a MASConstraintMaker with the callee view.
72 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
73 | * All constraints previously installed for the view will be removed.
74 | *
75 | * @param block scope within which you can build up the constraints which you wish to apply to the view.
76 | *
77 | * @return Array of created/updated MASConstraints
78 | */
79 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block;
80 |
81 | @end
82 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/category/UIView+AverageRange.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+AverageRange.m
3 | // WeTime
4 | //
5 | // Created by Aevitx on 14/11/29.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 | // from http://adad184.com/2014/09/28/use-masonry-to-quick-solve-autolayout/
9 |
10 | #import "UIView+AverageRange.h"
11 | #import "Masonry.h"
12 |
13 | @implementation UIView (AverageRange)
14 |
15 | /**
16 | * 水平方向,平均分布views
17 | *
18 | * @param views 所有子views
19 | */
20 | - (void)distributeSpacingHorizontallyWith:(NSArray*)views
21 | {
22 | NSMutableArray *spaces = [NSMutableArray arrayWithCapacity:views.count+1];
23 |
24 | for ( int i = 0 ; i < views.count+1 ; ++i )
25 | {
26 | UIView *v = [UIView new];
27 | [spaces addObject:v];
28 | [self addSubview:v];
29 |
30 | [v mas_makeConstraints:^(MASConstraintMaker *make) {
31 | make.width.equalTo(v.mas_height);
32 | }];
33 | }
34 |
35 | UIView *v0 = spaces[0];
36 |
37 | __weak __typeof(&*self)ws = self;
38 |
39 | [v0 mas_makeConstraints:^(MASConstraintMaker *make) {
40 | make.left.equalTo(ws.mas_left);
41 | make.centerY.equalTo(((UIView*)views[0]).mas_centerY);
42 | }];
43 |
44 | UIView *lastSpace = v0;
45 | for ( int i = 0 ; i < views.count; ++i )
46 | {
47 | UIView *obj = views[i];
48 | UIView *space = spaces[i+1];
49 |
50 | [obj mas_makeConstraints:^(MASConstraintMaker *make) {
51 | make.left.equalTo(lastSpace.mas_right);
52 | }];
53 |
54 | [space mas_makeConstraints:^(MASConstraintMaker *make) {
55 | make.left.equalTo(obj.mas_right);
56 | make.centerY.equalTo(obj.mas_centerY);
57 | make.width.equalTo(v0);
58 | }];
59 |
60 | lastSpace = space;
61 | }
62 |
63 | [lastSpace mas_makeConstraints:^(MASConstraintMaker *make) {
64 | make.right.equalTo(ws.mas_right);
65 | }];
66 |
67 | }
68 |
69 | /**
70 | * 竖直方向,平均分布views
71 | *
72 | * @param views 所有子views
73 | */
74 | - (void)distributeSpacingVerticallyWith:(NSArray*)views
75 | {
76 | NSMutableArray *spaces = [NSMutableArray arrayWithCapacity:views.count+1];
77 |
78 | for ( int i = 0 ; i < views.count+1 ; ++i )
79 | {
80 | UIView *v = [UIView new];
81 | [spaces addObject:v];
82 | [self addSubview:v];
83 |
84 | [v mas_makeConstraints:^(MASConstraintMaker *make) {
85 | make.width.equalTo(v.mas_height);
86 | }];
87 | }
88 |
89 |
90 | UIView *v0 = spaces[0];
91 |
92 | __weak __typeof(&*self)ws = self;
93 |
94 | [v0 mas_makeConstraints:^(MASConstraintMaker *make) {
95 | make.top.equalTo(ws.mas_top);
96 | make.centerX.equalTo(((UIView*)views[0]).mas_centerX);
97 | }];
98 |
99 | UIView *lastSpace = v0;
100 | for ( int i = 0 ; i < views.count; ++i )
101 | {
102 | UIView *obj = views[i];
103 | UIView *space = spaces[i+1];
104 |
105 | [obj mas_makeConstraints:^(MASConstraintMaker *make) {
106 | make.top.equalTo(lastSpace.mas_bottom);
107 | }];
108 |
109 | [space mas_makeConstraints:^(MASConstraintMaker *make) {
110 | make.top.equalTo(obj.mas_bottom);
111 | make.centerX.equalTo(obj.mas_centerX);
112 | make.height.equalTo(v0);
113 | }];
114 |
115 | lastSpace = space;
116 | }
117 |
118 | [lastSpace mas_makeConstraints:^(MASConstraintMaker *make) {
119 | make.bottom.equalTo(ws.mas_bottom);
120 | }];
121 | }
122 |
123 | @end
124 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/views/AutoResizeCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // AutoResizeCell.m
3 | // AutoResizeCellDemo
4 | //
5 | // Created by Aevitx on 14/12/3.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import "AutoResizeCell.h"
10 | #import "Masonry.h"
11 |
12 | #define kLabelHorizontalInsets 15.0f
13 | #define kLabelVerticalInsets 5.0f
14 |
15 | @interface AutoResizeCell ()
16 |
17 | @property (nonatomic, assign) BOOL didSetupConstraints;
18 |
19 | @end
20 |
21 | @implementation AutoResizeCell
22 |
23 | - (void)awakeFromNib {
24 | // Initialization code
25 | }
26 |
27 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
28 | [super setSelected:selected animated:animated];
29 |
30 | // Configure the view for the selected state
31 | }
32 |
33 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
34 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
35 | if (self) {
36 |
37 | // titleLabel
38 | if (!_titleLabel) {
39 | UILabel *aLbl = [[UILabel alloc] init];
40 | aLbl.numberOfLines = 0;
41 | aLbl.font = [UIFont systemFontOfSize:16];
42 | aLbl.textColor = [UIColor blackColor];
43 | aLbl.backgroundColor = [UIColor clearColor];
44 | [self.contentView addSubview:aLbl];
45 | self.titleLabel = aLbl;
46 | }
47 |
48 | // bodyLabel
49 | if (!_bodyLabel) {
50 | UILabel *aLbl = [[UILabel alloc] init];
51 | aLbl.numberOfLines = 0;
52 | aLbl.font = [UIFont systemFontOfSize:14];
53 | aLbl.textColor = [UIColor blackColor];
54 | aLbl.backgroundColor = [UIColor clearColor];
55 | [self.contentView addSubview:aLbl];
56 | self.bodyLabel = aLbl;
57 | }
58 |
59 | [self setNeedsUpdateConstraints];
60 | [self updateConstraintsIfNeeded];
61 | }
62 | return self;
63 | }
64 |
65 | - (void)layoutSubviews {
66 | [super layoutSubviews];
67 |
68 | /////////////// step: 6 ///////////////
69 | [self.contentView setNeedsLayout];
70 | [self.contentView layoutIfNeeded];
71 |
72 | _titleLabel.preferredMaxLayoutWidth = CGRectGetWidth(_titleLabel.frame);
73 | _bodyLabel.preferredMaxLayoutWidth = CGRectGetWidth(_bodyLabel.frame);
74 | /////////////// step: 6 ///////////////
75 | }
76 |
77 | - (void)updateConstraints {
78 |
79 | /////////////// step: 5 ///////////////
80 | if (!self.didSetupConstraints) {
81 |
82 | // titleLabel
83 | [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
84 | make.top.mas_equalTo(kLabelVerticalInsets);
85 | make.left.mas_equalTo(kLabelHorizontalInsets);
86 | make.right.mas_equalTo(-kLabelHorizontalInsets); // need
87 | }];
88 | // bodyLabel
89 | [_bodyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
90 | make.top.mas_equalTo(_titleLabel.mas_bottom).with.offset(kLabelVerticalInsets);
91 | make.left.mas_equalTo(_titleLabel.mas_left);
92 | make.bottom.mas_equalTo(-kLabelVerticalInsets); // need
93 | make.right.mas_equalTo(_titleLabel.mas_right);
94 | }];
95 | self.didSetupConstraints = YES;
96 | }
97 | [super updateConstraints];
98 | /////////////// step: 5 ///////////////
99 | }
100 |
101 | - (void)initModel:(id)model {
102 |
103 | self.titleLabel.text = [model objectForKey:@"title"];
104 | self.bodyLabel.text = [model objectForKey:@"content"];
105 |
106 | // Make sure the constraints have been added to this cell, since it may have just been created from scratch
107 | /////////////// step: 4 ///////////////
108 | [self setNeedsUpdateConstraints];
109 | [self updateConstraintsIfNeeded];
110 | /////////////// step: 4 ///////////////
111 | }
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 | @end
121 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASConstraintMaker.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraintBuilder.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraint.h"
10 | #import "MASUtilities.h"
11 |
12 | typedef NS_OPTIONS(NSInteger, MASAttribute) {
13 | MASAttributeLeft = 1 << NSLayoutAttributeLeft,
14 | MASAttributeRight = 1 << NSLayoutAttributeRight,
15 | MASAttributeTop = 1 << NSLayoutAttributeTop,
16 | MASAttributeBottom = 1 << NSLayoutAttributeBottom,
17 | MASAttributeLeading = 1 << NSLayoutAttributeLeading,
18 | MASAttributeTrailing = 1 << NSLayoutAttributeTrailing,
19 | MASAttributeWidth = 1 << NSLayoutAttributeWidth,
20 | MASAttributeHeight = 1 << NSLayoutAttributeHeight,
21 | MASAttributeCenterX = 1 << NSLayoutAttributeCenterX,
22 | MASAttributeCenterY = 1 << NSLayoutAttributeCenterY,
23 | MASAttributeBaseline = 1 << NSLayoutAttributeBaseline,
24 | };
25 |
26 | /**
27 | * Provides factory methods for creating MASConstraints.
28 | * Constraints are collected until they are ready to be installed
29 | *
30 | */
31 | @interface MASConstraintMaker : NSObject
32 |
33 | /**
34 | * The following properties return a new MASViewConstraint
35 | * with the first item set to the makers associated view and the appropriate MASViewAttribute
36 | */
37 | @property (nonatomic, strong, readonly) MASConstraint *left;
38 | @property (nonatomic, strong, readonly) MASConstraint *top;
39 | @property (nonatomic, strong, readonly) MASConstraint *right;
40 | @property (nonatomic, strong, readonly) MASConstraint *bottom;
41 | @property (nonatomic, strong, readonly) MASConstraint *leading;
42 | @property (nonatomic, strong, readonly) MASConstraint *trailing;
43 | @property (nonatomic, strong, readonly) MASConstraint *width;
44 | @property (nonatomic, strong, readonly) MASConstraint *height;
45 | @property (nonatomic, strong, readonly) MASConstraint *centerX;
46 | @property (nonatomic, strong, readonly) MASConstraint *centerY;
47 | @property (nonatomic, strong, readonly) MASConstraint *baseline;
48 |
49 | /**
50 | * Returns a block which creates a new MASCompositeConstraint with the first item set
51 | * to the makers associated view and children corresponding to the set bits in the
52 | * MASAttribute parameter. Combine multiple attributes via binary-or.
53 | */
54 | @property (nonatomic, strong, readonly) MASConstraint *(^attributes)(MASAttribute attrs);
55 |
56 | /**
57 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges
58 | * which generates the appropriate MASViewConstraint children (top, left, bottom, right)
59 | * with the first item set to the makers associated view
60 | */
61 | @property (nonatomic, strong, readonly) MASConstraint *edges;
62 |
63 | /**
64 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize
65 | * which generates the appropriate MASViewConstraint children (width, height)
66 | * with the first item set to the makers associated view
67 | */
68 | @property (nonatomic, strong, readonly) MASConstraint *size;
69 |
70 | /**
71 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter
72 | * which generates the appropriate MASViewConstraint children (centerX, centerY)
73 | * with the first item set to the makers associated view
74 | */
75 | @property (nonatomic, strong, readonly) MASConstraint *center;
76 |
77 | /**
78 | * Whether or not to check for an existing constraint instead of adding constraint
79 | */
80 | @property (nonatomic, assign) BOOL updateExisting;
81 |
82 | /**
83 | * Whether or not to remove existing constraints prior to installing
84 | */
85 | @property (nonatomic, assign) BOOL removeExisting;
86 |
87 | /**
88 | * initialises the maker with a default view
89 | *
90 | * @param view any MASConstrait are created with this view as the first item
91 | *
92 | * @return a new MASConstraintMaker
93 | */
94 | - (id)initWithView:(MAS_VIEW *)view;
95 |
96 | /**
97 | * Calls install method on any MASConstraints which have been created by this maker
98 | *
99 | * @return an array of all the installed MASConstraints
100 | */
101 | - (NSArray *)install;
102 |
103 | - (MASConstraint * (^)(dispatch_block_t))group;
104 |
105 | @end
106 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/View+MASAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+MASAdditions.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "View+MASAdditions.h"
10 | #import
11 |
12 | @implementation MAS_VIEW (MASAdditions)
13 |
14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *))block {
15 | self.translatesAutoresizingMaskIntoConstraints = NO;
16 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
17 | block(constraintMaker);
18 | return [constraintMaker install];
19 | }
20 |
21 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *))block {
22 | self.translatesAutoresizingMaskIntoConstraints = NO;
23 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
24 | constraintMaker.updateExisting = YES;
25 | block(constraintMaker);
26 | return [constraintMaker install];
27 | }
28 |
29 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block {
30 | self.translatesAutoresizingMaskIntoConstraints = NO;
31 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
32 | constraintMaker.removeExisting = YES;
33 | block(constraintMaker);
34 | return [constraintMaker install];
35 | }
36 |
37 | #pragma mark - NSLayoutAttribute properties
38 |
39 | - (MASViewAttribute *)mas_left {
40 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeft];
41 | }
42 |
43 | - (MASViewAttribute *)mas_top {
44 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTop];
45 | }
46 |
47 | - (MASViewAttribute *)mas_right {
48 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRight];
49 | }
50 |
51 | - (MASViewAttribute *)mas_bottom {
52 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottom];
53 | }
54 |
55 | - (MASViewAttribute *)mas_leading {
56 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeading];
57 | }
58 |
59 | - (MASViewAttribute *)mas_trailing {
60 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailing];
61 | }
62 |
63 | - (MASViewAttribute *)mas_width {
64 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeWidth];
65 | }
66 |
67 | - (MASViewAttribute *)mas_height {
68 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeHeight];
69 | }
70 |
71 | - (MASViewAttribute *)mas_centerX {
72 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterX];
73 | }
74 |
75 | - (MASViewAttribute *)mas_centerY {
76 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterY];
77 | }
78 |
79 | - (MASViewAttribute *)mas_baseline {
80 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBaseline];
81 | }
82 |
83 | - (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute
84 | {
85 | return ^(NSLayoutAttribute attr) {
86 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:attr];
87 | };
88 | }
89 |
90 | #pragma mark - associated properties
91 |
92 | - (id)mas_key {
93 | return objc_getAssociatedObject(self, @selector(mas_key));
94 | }
95 |
96 | - (void)setMas_key:(id)key {
97 | objc_setAssociatedObject(self, @selector(mas_key), key, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
98 | }
99 |
100 | #pragma mark - heirachy
101 |
102 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view {
103 | MAS_VIEW *closestCommonSuperview = nil;
104 |
105 | MAS_VIEW *secondViewSuperview = view;
106 | while (!closestCommonSuperview && secondViewSuperview) {
107 | MAS_VIEW *firstViewSuperview = self;
108 | while (!closestCommonSuperview && firstViewSuperview) {
109 | if (secondViewSuperview == firstViewSuperview) {
110 | closestCommonSuperview = secondViewSuperview;
111 | }
112 | firstViewSuperview = firstViewSuperview.superview;
113 | }
114 | secondViewSuperview = secondViewSuperview.superview;
115 | }
116 | return closestCommonSuperview;
117 | }
118 |
119 | @end
120 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/views/SecondResizeCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // SecondResizeCell.m
3 | // AutoResizeCellDemo
4 | //
5 | // Created by Aevitx on 14/12/11.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import "SecondResizeCell.h"
10 | #import "Masonry.h"
11 |
12 | #define kLabelHorizontalInsets 15.0f
13 | #define kLabelVerticalInsets 8.0f
14 |
15 | @interface SecondResizeCell ()
16 |
17 | @property (nonatomic, assign) BOOL didSetupConstraints;
18 |
19 | @end
20 |
21 | @implementation SecondResizeCell
22 |
23 | - (void)awakeFromNib {
24 | // Initialization code
25 | }
26 |
27 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
28 | [super setSelected:selected animated:animated];
29 |
30 | // Configure the view for the selected state
31 | }
32 |
33 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
34 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
35 | if (self) {
36 |
37 | // avatarImgView
38 | if (!_avatarImgView) {
39 | UIImageView *imgView = [[UIImageView alloc] init];
40 | imgView.contentMode = UIViewContentModeScaleAspectFill;
41 | imgView.backgroundColor = [UIColor lightGrayColor];
42 | [self.contentView addSubview:imgView];
43 | self.avatarImgView = imgView;
44 | }
45 |
46 | // titleLabel
47 | if (!_titleLabel) {
48 | UILabel *aLbl = [[UILabel alloc] init];
49 | aLbl.numberOfLines = 0;
50 | aLbl.font = [UIFont systemFontOfSize:18];
51 | aLbl.textColor = [UIColor blackColor];
52 | aLbl.backgroundColor = [UIColor clearColor];
53 | [self.contentView addSubview:aLbl];
54 | self.titleLabel = aLbl;
55 | }
56 |
57 | // bodyLabel
58 | if (!_bodyLabel) {
59 | UILabel *aLbl = [[UILabel alloc] init];
60 | aLbl.numberOfLines = 0;
61 | aLbl.font = [UIFont systemFontOfSize:14];
62 | aLbl.textColor = [UIColor blackColor];
63 | aLbl.backgroundColor = [UIColor clearColor];
64 | [self.contentView addSubview:aLbl];
65 | self.bodyLabel = aLbl;
66 | }
67 |
68 | [self setNeedsUpdateConstraints];
69 | [self updateConstraintsIfNeeded];
70 | }
71 | return self;
72 | }
73 |
74 | - (void)layoutSubviews {
75 | [super layoutSubviews];
76 |
77 | [self.contentView setNeedsLayout];
78 | [self.contentView layoutIfNeeded];
79 |
80 | _titleLabel.preferredMaxLayoutWidth = CGRectGetWidth(_titleLabel.frame);
81 | _bodyLabel.preferredMaxLayoutWidth = CGRectGetWidth(_bodyLabel.frame);
82 | }
83 |
84 | - (void)updateConstraints {
85 |
86 | if (!self.didSetupConstraints) {
87 |
88 | // avatarImgView
89 | if (self.avatarImgView) {
90 | [_avatarImgView mas_makeConstraints:^(MASConstraintMaker *make) {
91 | make.top.mas_equalTo(kLabelVerticalInsets);
92 | make.left.mas_equalTo(kLabelHorizontalInsets);
93 | make.right.mas_equalTo(_titleLabel.mas_left).with.offset(-kLabelHorizontalInsets);
94 | make.size.mas_equalTo(CGSizeMake(40, 40));
95 | }];
96 | }
97 |
98 | // titleLabel
99 | [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
100 | if (_avatarImgView) {
101 | make.top.mas_equalTo(_avatarImgView);
102 | make.left.mas_equalTo(_avatarImgView.mas_right).with.offset(kLabelHorizontalInsets);
103 | } else {
104 | make.top.mas_equalTo(kLabelVerticalInsets);
105 | make.left.mas_equalTo(kLabelHorizontalInsets);
106 | }
107 | make.right.mas_equalTo(-kLabelHorizontalInsets); // need
108 | }];
109 |
110 | // bodyLabel
111 | [_bodyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
112 | make.top.mas_equalTo(_titleLabel.mas_bottom).with.offset(kLabelVerticalInsets);
113 | make.left.mas_equalTo(_titleLabel.mas_left);
114 | make.bottom.mas_equalTo(-kLabelVerticalInsets); // need
115 | make.right.mas_equalTo(_titleLabel.mas_right);
116 | }];
117 | self.didSetupConstraints = YES;
118 | }
119 | [super updateConstraints];
120 | }
121 |
122 | - (void)initModel:(id)model {
123 |
124 | if (self.avatarImgView) {
125 | self.avatarImgView.image = [UIImage imageNamed:@"avatar.jpeg"];
126 | }
127 | self.titleLabel.text = [model objectForKey:@"title"];
128 | self.bodyLabel.text = [model objectForKey:@"content"];
129 |
130 | // Make sure the constraints have been added to this cell, since it may have just been created from scratch
131 | [self setNeedsUpdateConstraints];
132 | [self updateConstraintsIfNeeded];
133 | }
134 |
135 | @end
136 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASCompositeConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASCompositeConstraint.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASCompositeConstraint.h"
10 | #import "MASConstraint+Private.h"
11 |
12 | @interface MASCompositeConstraint ()
13 |
14 | @property (nonatomic, strong) id mas_key;
15 | @property (nonatomic, strong) NSMutableArray *childConstraints;
16 |
17 | @end
18 |
19 | @implementation MASCompositeConstraint
20 |
21 | - (id)initWithChildren:(NSArray *)children {
22 | self = [super init];
23 | if (!self) return nil;
24 |
25 | _childConstraints = [children mutableCopy];
26 | for (MASConstraint *constraint in _childConstraints) {
27 | constraint.delegate = self;
28 | }
29 |
30 | return self;
31 | }
32 |
33 | #pragma mark - MASConstraintDelegate
34 |
35 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint {
36 | NSUInteger index = [self.childConstraints indexOfObject:constraint];
37 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint);
38 | [self.childConstraints replaceObjectAtIndex:index withObject:replacementConstraint];
39 | }
40 |
41 | - (MASConstraint *)constraint:(MASConstraint __unused *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
42 | id strongDelegate = self.delegate;
43 | MASConstraint *newConstraint = [strongDelegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
44 | newConstraint.delegate = self;
45 | [self.childConstraints addObject:newConstraint];
46 | return newConstraint;
47 | }
48 |
49 | #pragma mark - NSLayoutConstraint multiplier proxies
50 |
51 | - (MASConstraint * (^)(CGFloat))multipliedBy {
52 | return ^id(CGFloat multiplier) {
53 | for (MASConstraint *constraint in self.childConstraints) {
54 | constraint.multipliedBy(multiplier);
55 | }
56 | return self;
57 | };
58 | }
59 |
60 | - (MASConstraint * (^)(CGFloat))dividedBy {
61 | return ^id(CGFloat divider) {
62 | for (MASConstraint *constraint in self.childConstraints) {
63 | constraint.dividedBy(divider);
64 | }
65 | return self;
66 | };
67 | }
68 |
69 | #pragma mark - MASLayoutPriority proxy
70 |
71 | - (MASConstraint * (^)(MASLayoutPriority))priority {
72 | return ^id(MASLayoutPriority priority) {
73 | for (MASConstraint *constraint in self.childConstraints) {
74 | constraint.priority(priority);
75 | }
76 | return self;
77 | };
78 | }
79 |
80 | #pragma mark - NSLayoutRelation proxy
81 |
82 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation {
83 | return ^id(id attr, NSLayoutRelation relation) {
84 | for (MASConstraint *constraint in self.childConstraints.copy) {
85 | constraint.equalToWithRelation(attr, relation);
86 | }
87 | return self;
88 | };
89 | }
90 |
91 | #pragma mark - attribute chaining
92 |
93 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
94 | [self constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
95 | return self;
96 | }
97 |
98 | #pragma mark - Animator proxy
99 |
100 | #if TARGET_OS_MAC && !TARGET_OS_IPHONE
101 |
102 | - (MASConstraint *)animator {
103 | for (MASConstraint *constraint in self.childConstraints) {
104 | [constraint animator];
105 | }
106 | return self;
107 | }
108 |
109 | #endif
110 |
111 | #pragma mark - debug helpers
112 |
113 | - (MASConstraint * (^)(id))key {
114 | return ^id(id key) {
115 | self.mas_key = key;
116 | int i = 0;
117 | for (MASConstraint *constraint in self.childConstraints) {
118 | constraint.key([NSString stringWithFormat:@"%@[%d]", key, i++]);
119 | }
120 | return self;
121 | };
122 | }
123 |
124 | #pragma mark - NSLayoutConstraint constant setters
125 |
126 | - (void)setInsets:(MASEdgeInsets)insets {
127 | for (MASConstraint *constraint in self.childConstraints) {
128 | constraint.insets = insets;
129 | }
130 | }
131 |
132 | - (void)setOffset:(CGFloat)offset {
133 | for (MASConstraint *constraint in self.childConstraints) {
134 | constraint.offset = offset;
135 | }
136 | }
137 |
138 | - (void)setSizeOffset:(CGSize)sizeOffset {
139 | for (MASConstraint *constraint in self.childConstraints) {
140 | constraint.sizeOffset = sizeOffset;
141 | }
142 | }
143 |
144 | - (void)setCenterOffset:(CGPoint)centerOffset {
145 | for (MASConstraint *constraint in self.childConstraints) {
146 | constraint.centerOffset = centerOffset;
147 | }
148 | }
149 |
150 | #pragma mark - MASConstraint
151 |
152 | - (void)install {
153 | for (MASConstraint *constraint in self.childConstraints) {
154 | constraint.updateExisting = self.updateExisting;
155 | [constraint install];
156 | }
157 | }
158 |
159 | - (void)uninstall {
160 | for (MASConstraint *constraint in self.childConstraints) {
161 | [constraint uninstall];
162 | }
163 | }
164 |
165 | @end
166 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/NSLayoutConstraint+MASDebugAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSLayoutConstraint+MASDebugAdditions.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "NSLayoutConstraint+MASDebugAdditions.h"
10 | #import "MASConstraint.h"
11 | #import "MASLayoutConstraint.h"
12 |
13 | @implementation NSLayoutConstraint (MASDebugAdditions)
14 |
15 | #pragma mark - description maps
16 |
17 | + (NSDictionary *)layoutRelationDescriptionsByValue {
18 | static dispatch_once_t once;
19 | static NSDictionary *descriptionMap;
20 | dispatch_once(&once, ^{
21 | descriptionMap = @{
22 | @(NSLayoutRelationEqual) : @"==",
23 | @(NSLayoutRelationGreaterThanOrEqual) : @">=",
24 | @(NSLayoutRelationLessThanOrEqual) : @"<=",
25 | };
26 | });
27 | return descriptionMap;
28 | }
29 |
30 | + (NSDictionary *)layoutAttributeDescriptionsByValue {
31 | static dispatch_once_t once;
32 | static NSDictionary *descriptionMap;
33 | dispatch_once(&once, ^{
34 | descriptionMap = @{
35 | @(NSLayoutAttributeTop) : @"top",
36 | @(NSLayoutAttributeLeft) : @"left",
37 | @(NSLayoutAttributeBottom) : @"bottom",
38 | @(NSLayoutAttributeRight) : @"right",
39 | @(NSLayoutAttributeLeading) : @"leading",
40 | @(NSLayoutAttributeTrailing) : @"trailing",
41 | @(NSLayoutAttributeWidth) : @"width",
42 | @(NSLayoutAttributeHeight) : @"height",
43 | @(NSLayoutAttributeCenterX) : @"centerX",
44 | @(NSLayoutAttributeCenterY) : @"centerY",
45 | @(NSLayoutAttributeBaseline) : @"baseline",
46 | };
47 |
48 | });
49 | return descriptionMap;
50 | }
51 |
52 |
53 | + (NSDictionary *)layoutPriorityDescriptionsByValue {
54 | static dispatch_once_t once;
55 | static NSDictionary *descriptionMap;
56 | dispatch_once(&once, ^{
57 | #if TARGET_OS_IPHONE
58 | descriptionMap = @{
59 | @(MASLayoutPriorityDefaultHigh) : @"high",
60 | @(MASLayoutPriorityDefaultLow) : @"low",
61 | @(MASLayoutPriorityDefaultMedium) : @"medium",
62 | @(MASLayoutPriorityRequired) : @"required",
63 | @(MASLayoutPriorityFittingSizeLevel) : @"fitting size",
64 | };
65 | #elif TARGET_OS_MAC
66 | descriptionMap = @{
67 | @(MASLayoutPriorityDefaultHigh) : @"high",
68 | @(MASLayoutPriorityDragThatCanResizeWindow) : @"drag can resize window",
69 | @(MASLayoutPriorityDefaultMedium) : @"medium",
70 | @(MASLayoutPriorityWindowSizeStayPut) : @"window size stay put",
71 | @(MASLayoutPriorityDragThatCannotResizeWindow) : @"drag cannot resize window",
72 | @(MASLayoutPriorityDefaultLow) : @"low",
73 | @(MASLayoutPriorityFittingSizeCompression) : @"fitting size",
74 | @(MASLayoutPriorityRequired) : @"required",
75 | };
76 | #endif
77 | });
78 | return descriptionMap;
79 | }
80 |
81 | #pragma mark - description override
82 |
83 | + (NSString *)descriptionForObject:(id)obj {
84 | if ([obj respondsToSelector:@selector(mas_key)] && [obj mas_key]) {
85 | return [NSString stringWithFormat:@"%@:%@", [obj class], [obj mas_key]];
86 | }
87 | return [NSString stringWithFormat:@"%@:%p", [obj class], obj];
88 | }
89 |
90 | - (NSString *)description {
91 | NSMutableString *description = [[NSMutableString alloc] initWithString:@"<"];
92 |
93 | [description appendString:[self.class descriptionForObject:self]];
94 |
95 | [description appendFormat:@" %@", [self.class descriptionForObject:self.firstItem]];
96 | if (self.firstAttribute != NSLayoutAttributeNotAnAttribute) {
97 | [description appendFormat:@".%@", [self.class.layoutAttributeDescriptionsByValue objectForKey:@(self.firstAttribute)]];
98 | }
99 |
100 | [description appendFormat:@" %@", [self.class.layoutRelationDescriptionsByValue objectForKey:@(self.relation)]];
101 |
102 | if (self.secondItem) {
103 | [description appendFormat:@" %@", [self.class descriptionForObject:self.secondItem]];
104 | }
105 | if (self.secondAttribute != NSLayoutAttributeNotAnAttribute) {
106 | [description appendFormat:@".%@", [self.class.layoutAttributeDescriptionsByValue objectForKey:@(self.secondAttribute)]];
107 | }
108 |
109 | if (self.multiplier != 1) {
110 | [description appendFormat:@" * %g", self.multiplier];
111 | }
112 |
113 | if (self.constant) {
114 | if (self.secondAttribute == NSLayoutAttributeNotAnAttribute) {
115 | [description appendFormat:@" %g", self.constant];
116 | } else {
117 | [description appendFormat:@" %@ %g", (self.constant < 0 ? @"-" : @"+"), ABS(self.constant)];
118 | }
119 | }
120 |
121 | if (self.priority != MASLayoutPriorityRequired) {
122 | [description appendFormat:@" ^%@", [self.class.layoutPriorityDescriptionsByValue objectForKey:@(self.priority)] ?: [NSNumber numberWithDouble:self.priority]];
123 | }
124 |
125 | [description appendString:@">"];
126 | return description;
127 | }
128 |
129 | @end
130 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/controllers/AutoResizeTableController.m:
--------------------------------------------------------------------------------
1 | //
2 | // AutoResizeTableController.m
3 | // AutoResizeCellDemo
4 | //
5 | // Created by Aevitx on 14/12/3.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import "AutoResizeTableController.h"
10 | #import "AutoResizeCell.h"
11 |
12 | #define CELL_CACHE_KEY_SC(indexPath) [NSString stringWithFormat:@"%ld-%ld", (long)indexPath.section, (long)indexPath.row]
13 |
14 | static NSString *autoResizeCellId = @"autoResizeCellId";
15 |
16 | @interface AutoResizeTableController ()
17 |
18 | @property (nonatomic, strong) UITableView *myTableView;
19 | @property (nonatomic, strong) NSMutableDictionary *cellCacheDict;
20 |
21 | @end
22 |
23 | @implementation AutoResizeTableController
24 |
25 | - (void)viewDidLoad {
26 | [super viewDidLoad];
27 |
28 | // Uncomment the following line to preserve selection between presentations.
29 | // self.clearsSelectionOnViewWillAppear = NO;
30 |
31 | // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
32 | // self.navigationItem.rightBarButtonItem = self.editButtonItem;
33 |
34 | self.title = @"auto resize cell";
35 |
36 | self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStylePlain target:self action:@selector(backBtnPressed:)];
37 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"reload" style:UIBarButtonItemStylePlain target:self action:@selector(reloadTable:)];
38 |
39 | self.cellCacheDict = [NSMutableDictionary dictionary];
40 | }
41 |
42 | - (void)didReceiveMemoryWarning {
43 | [super didReceiveMemoryWarning];
44 | // Dispose of any resources that can be recreated.
45 | }
46 |
47 | #pragma mark - actions
48 | - (void)backBtnPressed:(id)sender {
49 | [self.navigationController dismissViewControllerAnimated:YES completion:^{
50 | ;
51 | }];
52 | }
53 |
54 | - (void)reloadTable:(id)sender {
55 | [self.myTableView reloadData];
56 | }
57 |
58 | #pragma mark - tableview
59 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
60 | return 2;
61 | }
62 |
63 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
64 | AutoResizeCell *cell = [self getCellWithIndexPath:indexPath];
65 | [_cellCacheDict setObject:cell forKey:CELL_CACHE_KEY_SC(indexPath)];
66 |
67 | [cell setNeedsUpdateConstraints];
68 | [cell updateConstraintsIfNeeded];
69 | cell.bounds = CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), CGRectGetHeight(cell.bounds));
70 | [cell setNeedsLayout];
71 | [cell layoutIfNeeded];
72 |
73 | CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
74 | height += 1;
75 | return height;
76 | }
77 |
78 | - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
79 | AutoResizeCell *cell = [_cellCacheDict objectForKey:CELL_CACHE_KEY_SC(indexPath)];
80 | if (!cell) {
81 | return [self getCellWithIndexPath:indexPath];
82 | }
83 | return cell;
84 | }
85 |
86 | - (AutoResizeCell*)getCellWithIndexPath:(NSIndexPath*)indexPath {
87 | AutoResizeCell *cell = [self.myTableView dequeueReusableCellWithIdentifier:autoResizeCellId];
88 | if (!cell) {
89 | cell = [[AutoResizeCell alloc] init];
90 | }
91 | cell.titleLabel.text = @"标题";
92 | cell.bodyLabel.text = @"内容";
93 | return cell;
94 | }
95 |
96 | /*
97 | // Override to support conditional editing of the table view.
98 | - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
99 | // Return NO if you do not want the specified item to be editable.
100 | return YES;
101 | }
102 | */
103 |
104 | /*
105 | // Override to support editing the table view.
106 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
107 | if (editingStyle == UITableViewCellEditingStyleDelete) {
108 | // Delete the row from the data source
109 | [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
110 | } else if (editingStyle == UITableViewCellEditingStyleInsert) {
111 | // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
112 | }
113 | }
114 | */
115 |
116 | /*
117 | // Override to support rearranging the table view.
118 | - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
119 | }
120 | */
121 |
122 | /*
123 | // Override to support conditional rearranging of the table view.
124 | - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
125 | // Return NO if you do not want the item to be re-orderable.
126 | return YES;
127 | }
128 | */
129 |
130 | /*
131 | #pragma mark - Navigation
132 |
133 | // In a storyboard-based application, you will often want to do a little preparation before navigation
134 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
135 | // Get the new view controller using [segue destinationViewController].
136 | // Pass the selected object to the new view controller.
137 | }
138 | */
139 |
140 | @end
141 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASUtilities.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASUtilities.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 19/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #if TARGET_OS_IPHONE
12 |
13 | #import
14 | #define MAS_VIEW UIView
15 | #define MASEdgeInsets UIEdgeInsets
16 |
17 | typedef UILayoutPriority MASLayoutPriority;
18 | static const MASLayoutPriority MASLayoutPriorityRequired = UILayoutPriorityRequired;
19 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = UILayoutPriorityDefaultHigh;
20 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 500;
21 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = UILayoutPriorityDefaultLow;
22 | static const MASLayoutPriority MASLayoutPriorityFittingSizeLevel = UILayoutPriorityFittingSizeLevel;
23 |
24 | #elif TARGET_OS_MAC
25 |
26 | #import
27 | #define MAS_VIEW NSView
28 | #define MASEdgeInsets NSEdgeInsets
29 |
30 | typedef NSLayoutPriority MASLayoutPriority;
31 | static const MASLayoutPriority MASLayoutPriorityRequired = NSLayoutPriorityRequired;
32 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = NSLayoutPriorityDefaultHigh;
33 | static const MASLayoutPriority MASLayoutPriorityDragThatCanResizeWindow = NSLayoutPriorityDragThatCanResizeWindow;
34 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 501;
35 | static const MASLayoutPriority MASLayoutPriorityWindowSizeStayPut = NSLayoutPriorityWindowSizeStayPut;
36 | static const MASLayoutPriority MASLayoutPriorityDragThatCannotResizeWindow = NSLayoutPriorityDragThatCannotResizeWindow;
37 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = NSLayoutPriorityDefaultLow;
38 | static const MASLayoutPriority MASLayoutPriorityFittingSizeCompression = NSLayoutPriorityFittingSizeCompression;
39 |
40 | #endif
41 |
42 | /**
43 | * Allows you to attach keys to objects matching the variable names passed.
44 | *
45 | * view1.mas_key = @"view1", view2.mas_key = @"view2";
46 | *
47 | * is equivalent to:
48 | *
49 | * MASAttachKeys(view1, view2);
50 | */
51 | #define MASAttachKeys(...) \
52 | NSDictionary *keyPairs = NSDictionaryOfVariableBindings(__VA_ARGS__); \
53 | for (id key in keyPairs.allKeys) { \
54 | id obj = keyPairs[key]; \
55 | NSAssert([obj respondsToSelector:@selector(setMas_key:)], \
56 | @"Cannot attach mas_key to %@", obj); \
57 | [obj setMas_key:key]; \
58 | }
59 |
60 | /**
61 | * Used to create object hashes
62 | * Based on http://www.mikeash.com/pyblog/friday-qa-2010-06-18-implementing-equality-and-hashing.html
63 | */
64 | #define MAS_NSUINT_BIT (CHAR_BIT * sizeof(NSUInteger))
65 | #define MAS_NSUINTROTATE(val, howmuch) ((((NSUInteger)val) << howmuch) | (((NSUInteger)val) >> (MAS_NSUINT_BIT - howmuch)))
66 |
67 | /**
68 | * Given a scalar or struct value, wraps it in NSValue
69 | * Based on EXPObjectify: https://github.com/specta/expecta
70 | */
71 | static inline id _MASBoxValue(const char *type, ...) {
72 | va_list v;
73 | va_start(v, type);
74 | id obj = nil;
75 | if (strcmp(type, @encode(id)) == 0) {
76 | id actual = va_arg(v, id);
77 | obj = actual;
78 | } else if (strcmp(type, @encode(CGPoint)) == 0) {
79 | CGPoint actual = (CGPoint)va_arg(v, CGPoint);
80 | obj = [NSValue value:&actual withObjCType:type];
81 | } else if (strcmp(type, @encode(CGSize)) == 0) {
82 | CGSize actual = (CGSize)va_arg(v, CGSize);
83 | obj = [NSValue value:&actual withObjCType:type];
84 | } else if (strcmp(type, @encode(MASEdgeInsets)) == 0) {
85 | MASEdgeInsets actual = (MASEdgeInsets)va_arg(v, MASEdgeInsets);
86 | obj = [NSValue value:&actual withObjCType:type];
87 | } else if (strcmp(type, @encode(double)) == 0) {
88 | double actual = (double)va_arg(v, double);
89 | obj = [NSNumber numberWithDouble:actual];
90 | } else if (strcmp(type, @encode(float)) == 0) {
91 | float actual = (float)va_arg(v, double);
92 | obj = [NSNumber numberWithFloat:actual];
93 | } else if (strcmp(type, @encode(int)) == 0) {
94 | int actual = (int)va_arg(v, int);
95 | obj = [NSNumber numberWithInt:actual];
96 | } else if (strcmp(type, @encode(long)) == 0) {
97 | long actual = (long)va_arg(v, long);
98 | obj = [NSNumber numberWithLong:actual];
99 | } else if (strcmp(type, @encode(long long)) == 0) {
100 | long long actual = (long long)va_arg(v, long long);
101 | obj = [NSNumber numberWithLongLong:actual];
102 | } else if (strcmp(type, @encode(short)) == 0) {
103 | short actual = (short)va_arg(v, int);
104 | obj = [NSNumber numberWithShort:actual];
105 | } else if (strcmp(type, @encode(char)) == 0) {
106 | char actual = (char)va_arg(v, int);
107 | obj = [NSNumber numberWithChar:actual];
108 | } else if (strcmp(type, @encode(bool)) == 0) {
109 | bool actual = (bool)va_arg(v, int);
110 | obj = [NSNumber numberWithBool:actual];
111 | } else if (strcmp(type, @encode(unsigned char)) == 0) {
112 | unsigned char actual = (unsigned char)va_arg(v, unsigned int);
113 | obj = [NSNumber numberWithUnsignedChar:actual];
114 | } else if (strcmp(type, @encode(unsigned int)) == 0) {
115 | unsigned int actual = (unsigned int)va_arg(v, unsigned int);
116 | obj = [NSNumber numberWithUnsignedInt:actual];
117 | } else if (strcmp(type, @encode(unsigned long)) == 0) {
118 | unsigned long actual = (unsigned long)va_arg(v, unsigned long);
119 | obj = [NSNumber numberWithUnsignedLong:actual];
120 | } else if (strcmp(type, @encode(unsigned long long)) == 0) {
121 | unsigned long long actual = (unsigned long long)va_arg(v, unsigned long long);
122 | obj = [NSNumber numberWithUnsignedLongLong:actual];
123 | } else if (strcmp(type, @encode(unsigned short)) == 0) {
124 | unsigned short actual = (unsigned short)va_arg(v, unsigned int);
125 | obj = [NSNumber numberWithUnsignedShort:actual];
126 | }
127 | va_end(v);
128 | return obj;
129 | }
130 |
131 | #define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value))
132 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 22/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * Enables Constraints to be created with chainable syntax
13 | * Constraint can represent single NSLayoutConstraint (MASViewConstraint)
14 | * or a group of NSLayoutConstraints (MASComposisteConstraint)
15 | */
16 | @interface MASConstraint : NSObject
17 |
18 | // Chaining Support
19 |
20 | /**
21 | * Modifies the NSLayoutConstraint constant,
22 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
23 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
24 | */
25 | - (MASConstraint * (^)(MASEdgeInsets insets))insets;
26 |
27 | /**
28 | * Modifies the NSLayoutConstraint constant,
29 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
30 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight
31 | */
32 | - (MASConstraint * (^)(CGSize offset))sizeOffset;
33 |
34 | /**
35 | * Modifies the NSLayoutConstraint constant,
36 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
37 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
38 | */
39 | - (MASConstraint * (^)(CGPoint offset))centerOffset;
40 |
41 | /**
42 | * Modifies the NSLayoutConstraint constant
43 | */
44 | - (MASConstraint * (^)(CGFloat offset))offset;
45 |
46 | /**
47 | * Modifies the NSLayoutConstraint constant based on a value type
48 | */
49 | - (MASConstraint * (^)(NSValue *value))valueOffset;
50 |
51 | /**
52 | * Sets the NSLayoutConstraint multiplier property
53 | */
54 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy;
55 |
56 | /**
57 | * Sets the NSLayoutConstraint multiplier to 1.0/dividedBy
58 | */
59 | - (MASConstraint * (^)(CGFloat divider))dividedBy;
60 |
61 | /**
62 | * Sets the NSLayoutConstraint priority to a float or MASLayoutPriority
63 | */
64 | - (MASConstraint * (^)(MASLayoutPriority priority))priority;
65 |
66 | /**
67 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityLow
68 | */
69 | - (MASConstraint * (^)())priorityLow;
70 |
71 | /**
72 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityMedium
73 | */
74 | - (MASConstraint * (^)())priorityMedium;
75 |
76 | /**
77 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh
78 | */
79 | - (MASConstraint * (^)())priorityHigh;
80 |
81 | /**
82 | * Sets the constraint relation to NSLayoutRelationEqual
83 | * returns a block which accepts one of the following:
84 | * MASViewAttribute, UIView, NSValue, NSArray
85 | * see readme for more details.
86 | */
87 | - (MASConstraint * (^)(id attr))equalTo;
88 |
89 | /**
90 | * Sets the constraint relation to NSLayoutRelationGreaterThanOrEqual
91 | * returns a block which accepts one of the following:
92 | * MASViewAttribute, UIView, NSValue, NSArray
93 | * see readme for more details.
94 | */
95 | - (MASConstraint * (^)(id attr))greaterThanOrEqualTo;
96 |
97 | /**
98 | * Sets the constraint relation to NSLayoutRelationLessThanOrEqual
99 | * returns a block which accepts one of the following:
100 | * MASViewAttribute, UIView, NSValue, NSArray
101 | * see readme for more details.
102 | */
103 | - (MASConstraint * (^)(id attr))lessThanOrEqualTo;
104 |
105 | /**
106 | * Optional semantic property which has no effect but improves the readability of constraint
107 | */
108 | - (MASConstraint *)with;
109 |
110 | /**
111 | * optional semantic property which has no effect but improves the readability of constraint
112 | */
113 | - (MASConstraint *)and;
114 |
115 | /**
116 | * creates a new MASCompositeConstraint with the called attribute and reciever
117 | */
118 | - (MASConstraint *)left;
119 | - (MASConstraint *)top;
120 | - (MASConstraint *)right;
121 | - (MASConstraint *)bottom;
122 | - (MASConstraint *)leading;
123 | - (MASConstraint *)trailing;
124 | - (MASConstraint *)width;
125 | - (MASConstraint *)height;
126 | - (MASConstraint *)centerX;
127 | - (MASConstraint *)centerY;
128 | - (MASConstraint *)baseline;
129 |
130 | /**
131 | * Sets the constraint debug name
132 | */
133 | - (MASConstraint * (^)(id key))key;
134 |
135 | // NSLayoutConstraint constant Setters
136 | // for use outside of mas_updateConstraints/mas_makeConstraints blocks
137 |
138 | /**
139 | * Modifies the NSLayoutConstraint constant,
140 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
141 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
142 | */
143 | - (void)setInsets:(MASEdgeInsets)insets;
144 |
145 | /**
146 | * Modifies the NSLayoutConstraint constant,
147 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
148 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight
149 | */
150 | - (void)setSizeOffset:(CGSize)sizeOffset;
151 |
152 | /**
153 | * Modifies the NSLayoutConstraint constant,
154 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
155 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
156 | */
157 | - (void)setCenterOffset:(CGPoint)centerOffset;
158 |
159 | /**
160 | * Modifies the NSLayoutConstraint constant
161 | */
162 | - (void)setOffset:(CGFloat)offset;
163 |
164 |
165 | // NSLayoutConstraint Installation support
166 |
167 | #if TARGET_OS_MAC && !TARGET_OS_IPHONE
168 | /**
169 | * Whether or not to go through the animator proxy when modifying the constraint
170 | */
171 | @property (nonatomic, copy, readonly) MASConstraint *animator;
172 | #endif
173 |
174 | /**
175 | * Creates a NSLayoutConstraint and adds it to the appropriate view.
176 | */
177 | - (void)install;
178 |
179 | /**
180 | * Removes previously installed NSLayoutConstraint
181 | */
182 | - (void)uninstall;
183 |
184 | @end
185 |
186 |
187 | /**
188 | * Convenience auto-boxing macros for MASConstraint methods.
189 | *
190 | * Defining MAS_SHORTHAND_GLOBALS will turn on auto-boxing for default syntax.
191 | * A potential drawback of this is that the unprefixed macros will appear in global scope.
192 | */
193 | #define mas_equalTo(...) equalTo(MASBoxValue((__VA_ARGS__)))
194 | #define mas_greaterThanOrEqualTo(...) greaterThanOrEqualTo(MASBoxValue((__VA_ARGS__)))
195 | #define mas_lessThanOrEqualTo(...) lessThanOrEqualTo(MASBoxValue((__VA_ARGS__)))
196 |
197 | #define mas_offset(...) valueOffset(MASBoxValue((__VA_ARGS__)))
198 |
199 |
200 | #ifdef MAS_SHORTHAND_GLOBALS
201 |
202 | #define equalTo(...) mas_equalTo(__VA_ARGS__)
203 | #define greaterThanOrEqualTo(...) mas_greaterThanOrEqualTo(__VA_ARGS__)
204 | #define lessThanOrEqualTo(...) mas_lessThanOrEqualTo(__VA_ARGS__)
205 |
206 | #define offset(...) mas_offset(__VA_ARGS__)
207 |
208 | #endif
209 |
210 |
211 | @interface MASConstraint (AutoboxingSupport)
212 |
213 | /**
214 | * Aliases to corresponding relation methods (for shorthand macros)
215 | * Also needed to aid autocompletion
216 | */
217 | - (MASConstraint * (^)(id attr))mas_equalTo;
218 | - (MASConstraint * (^)(id attr))mas_greaterThanOrEqualTo;
219 | - (MASConstraint * (^)(id attr))mas_lessThanOrEqualTo;
220 |
221 | /**
222 | * A dummy method to aid autocompletion
223 | */
224 | - (MASConstraint * (^)(id offset))mas_offset;
225 |
226 | @end
227 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SCAutoResizeCellDemo
2 |
3 | > use autolayout on the tableview
4 | > 在tableview在使用autolayout,自适应cell的高度(iOS7+)
5 |
6 | ##一、概述
7 | ####1、声明`NSDictinary *offscreenCell`
8 |
9 | > a. 用来存储每种类型cell的一个对象实例
10 | > b. 此`dictionary`的`key`为每种类型cell的`reuse identifier`,`value`为该类型cell的一个对象实例
11 |
12 |
13 |
14 | ####2、cell的注册
15 |
16 | > a. 使用`tableview`的`registerClass`方法来进行cell的注册
17 | > b. 若有多种类型的cell,则要用`registerClass`注册多个cell
18 |
19 |
20 |
21 | ####3、初始化cell,并返回cell高度
22 |
23 | > a. 在`heightForRowAtIndexPath`方法里,进行cell的初始化
24 | > b. 使用`systemLayoutSizeFittingSize`方法获取cell的高度
25 |
26 |
27 |
28 | ####4、cell赋值
29 |
30 | > 在`cellForRowAtIndexPath`方法里,进行cell的赋值
31 |
32 |
33 |
34 | ####5、使用`autolayout`对需要的控件进行布局
35 |
36 | > 有两种方式:
37 | > a. 使用xib
38 | > b. 重写自定义cell类里的`updateConstraints`方法,手动用代码进行布局
39 |
40 | 注:本文使用[Masonry](https://github.com/Masonry/Masonry)进行布局
41 |
42 |
43 |
44 | ####6、通知系统进行布局
45 |
46 | > 在自定义的cell类里的`layoutSubviews`方法,调用相关方法通知系统进行布局
47 |
48 |
49 |
50 |
51 | ##二、关键点
52 | 1、autolayout要设置正确,如果不正确,`systemLayoutSizeFittingSize`方法计算出来的高度是0
53 |
54 | ##三、示例代码
55 |
56 | > 假设有两种类型的cell,先自定义两个cell类
57 | > 分别命名为`AutoResizeCell` `SecondResizeCell`
58 | > `reuse identify`分别为`autoResizeCellId` `secondResizeCellId`
59 |
60 |
61 |
62 | 1、在`controller`里的`viewDidLoad`
63 |
64 | ```
65 | /////////////// step: 1 ///////////////
66 | self.offscreenCell = [NSMutableDictionary dictionary];
67 | /////////////// step: 1 ///////////////
68 |
69 | /////////////// step: 2 ///////////////
70 | [self.myTableView registerClass:[AutoResizeCell class] forCellReuseIdentifier:autoResizeCellId];
71 | [self.myTableView registerClass:[SecondResizeCell class] forCellReuseIdentifier:secondResizeCellId];
72 | // Setting the estimated row height prevents the table view from calling tableView:heightForRowAtIndexPath: for every row in the table on first load;
73 | // it will only be called as cells are about to scroll onscreen. This is a major performance optimization.self.myTableView.estimatedRowHeight = UITableViewAutomaticDimension; // iOS7+
74 | /////////////// step: 2 ///////////////
75 | ```
76 |
77 |
78 |
79 | 2、在`controller`里的`heightForRowAtIndexPath`
80 |
81 | ```
82 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
83 |
84 | /////////////// step: 3 ///////////////
85 | NSDictionary *aDict = [self getRowDataDictInSection:indexPath.section row:indexPath.row];
86 | BOOL hasAvatar = [[aDict objectForKey:HAS_AVATAR] boolValue];
87 | NSString *reuseIdentifier = (hasAvatar ? secondResizeCellId : autoResizeCellId);
88 | UITableViewCell *cell = [self.offscreenCell objectForKey:reuseIdentifier];
89 | if (!cell) {
90 | if (hasAvatar) {
91 | cell = [[SecondResizeCell alloc] init];
92 | } else {
93 | cell = [[AutoResizeCell alloc] init];
94 | }
95 | [self.offscreenCell setObject:cell forKey:reuseIdentifier];
96 | }
97 | if (hasAvatar) {
98 | [(SecondResizeCell*)cell initModel:aDict];
99 | } else {
100 | [(AutoResizeCell*)cell initModel:aDict];
101 | }
102 | cell.bounds = CGRectMake(0.0f, 0.0f, CGRectGetWidth(tableView.bounds), CGRectGetHeight(cell.bounds));
103 | [cell setNeedsLayout];
104 | [cell layoutIfNeeded];
105 |
106 | CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
107 | height += 1;
108 | /////////////// step: 3 ///////////////
109 |
110 | return height;
111 | }
112 | ```
113 |
114 |
115 |
116 | 3、在`controller`里的`cellForRowAtIndexPath`
117 |
118 | ```
119 | - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
120 |
121 | /////////////// step: 4 ///////////////
122 | NSDictionary *aDict = [self getRowDataDictInSection:indexPath.section row:indexPath.row];
123 | BOOL hasAvatar = [[aDict objectForKey:HAS_AVATAR] boolValue];
124 | NSString *reuseIdentifier = (hasAvatar ? secondResizeCellId : autoResizeCellId);
125 | AutoResizeCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
126 | if (hasAvatar) {
127 | [(SecondResizeCell*)cell initModel:aDict];
128 | } else {
129 | [(AutoResizeCell*)cell initModel:aDict];
130 | }
131 | /////////////// step: 4 ///////////////
132 | return cell;
133 | }
134 | ```
135 |
136 |
137 |
138 | 4、在自定义cell类的`initModel`
139 |
140 | ```
141 | - (void)initModel:(id)model {
142 |
143 | self.titleLabel.text = [model objectForKey:@"title"];
144 | self.bodyLabel.text = [model objectForKey:@"content"];
145 |
146 | // Make sure the constraints have been added to this cell, since it may have just been created from scratch
147 | /////////////// step: 4 ///////////////
148 | [self setNeedsUpdateConstraints];
149 | [self updateConstraintsIfNeeded];
150 | /////////////// step: 4 ///////////////
151 | }
152 | ```
153 |
154 |
155 |
156 | 5、在自定义cell类的`updateConstraints`
157 |
158 | ```
159 | - (void)updateConstraints {
160 |
161 | /////////////// step: 5 ///////////////
162 | if (!self.didSetupConstraints) {
163 |
164 | // titleLabel
165 | [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
166 | make.top.mas_equalTo(kLabelVerticalInsets);
167 | make.left.mas_equalTo(kLabelHorizontalInsets);
168 | make.right.mas_equalTo(-kLabelHorizontalInsets); // need
169 | }];
170 | // bodyLabel
171 | [_bodyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
172 | make.top.mas_equalTo(_titleLabel.mas_bottom).with.offset(kLabelVerticalInsets);
173 | make.left.mas_equalTo(_titleLabel.mas_left);
174 | make.bottom.mas_equalTo(-kLabelVerticalInsets); // need
175 | make.right.mas_equalTo(_titleLabel.mas_right);
176 | }];
177 | self.didSetupConstraints = YES;
178 | }
179 | [super updateConstraints];
180 | /////////////// step: 5 ///////////////
181 | }
182 | ```
183 |
184 |
185 |
186 | 6、在自定义cell类的`layoutSubviews`
187 |
188 | ```
189 | - (void)layoutSubviews {
190 | [super layoutSubviews];
191 |
192 | /////////////// step: 6 ///////////////
193 | [self.contentView setNeedsLayout];
194 | [self.contentView layoutIfNeeded];
195 |
196 | _titleLabel.preferredMaxLayoutWidth = CGRectGetWidth(_titleLabel.frame);
197 | _bodyLabel.preferredMaxLayoutWidth = CGRectGetWidth(_bodyLabel.frame);
198 | /////////////// step: 6 ///////////////
199 | }
200 | ```
201 |
202 |
203 |
204 | ##四、autolayout相关资料
205 |
206 | 1)开始iOS 7中自动布局教程(上下部分)
207 | 1、http://www.cocoachina.com/industry/20131203/7462.html
208 | 2、http://www.cnblogs.com/zer0Black/p/3977288.html
209 |
210 |
211 | 2)Masonry说明:
212 | 官方:https://github.com/Masonry/Masonry
213 | 第三方:http://adad184.com/2014/09/28/use-masonry-to-quick-solve-autolayout/
214 |
215 |
216 | 3)tableview动态计算cell高度
217 | 1、 http://www.ifun.cc/blog/2014/02/21/dong-tai-ji-suan-uitableviewcellgao-du-xiang-jie/
218 | 2、http://www.devdiv.com/autolayout_uitableviewcell_-blog-21666-52543.html
219 | 3、http://www.tuicool.com/articles/FZN3q2
220 | 4、http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.m
3 | // Masonry
4 | //
5 | // Created by Nick Tymchenko on 1/20/14.
6 | //
7 |
8 | #import "MASConstraint.h"
9 | #import "MASConstraint+Private.h"
10 |
11 | #define MASMethodNotImplemented() \
12 | @throw [NSException exceptionWithName:NSInternalInconsistencyException \
13 | reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] \
14 | userInfo:nil]
15 |
16 | @implementation MASConstraint
17 |
18 | #pragma mark - Init
19 |
20 | - (id)init {
21 | NSAssert(![self isMemberOfClass:[MASConstraint class]], @"MASConstraint is an abstract class, you should not instantiate it directly.");
22 | return [super init];
23 | }
24 |
25 | #pragma mark - NSLayoutRelation proxies
26 |
27 | - (MASConstraint * (^)(id))equalTo {
28 | return ^id(id attribute) {
29 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual);
30 | };
31 | }
32 |
33 | - (MASConstraint * (^)(id))mas_equalTo {
34 | return ^id(id attribute) {
35 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual);
36 | };
37 | }
38 |
39 | - (MASConstraint * (^)(id))greaterThanOrEqualTo {
40 | return ^id(id attribute) {
41 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual);
42 | };
43 | }
44 |
45 | - (MASConstraint * (^)(id))mas_greaterThanOrEqualTo {
46 | return ^id(id attribute) {
47 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual);
48 | };
49 | }
50 |
51 | - (MASConstraint * (^)(id))lessThanOrEqualTo {
52 | return ^id(id attribute) {
53 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual);
54 | };
55 | }
56 |
57 | - (MASConstraint * (^)(id))mas_lessThanOrEqualTo {
58 | return ^id(id attribute) {
59 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual);
60 | };
61 | }
62 |
63 | #pragma mark - MASLayoutPriority proxies
64 |
65 | - (MASConstraint * (^)())priorityLow {
66 | return ^id{
67 | self.priority(MASLayoutPriorityDefaultLow);
68 | return self;
69 | };
70 | }
71 |
72 | - (MASConstraint * (^)())priorityMedium {
73 | return ^id{
74 | self.priority(MASLayoutPriorityDefaultMedium);
75 | return self;
76 | };
77 | }
78 |
79 | - (MASConstraint * (^)())priorityHigh {
80 | return ^id{
81 | self.priority(MASLayoutPriorityDefaultHigh);
82 | return self;
83 | };
84 | }
85 |
86 | #pragma mark - NSLayoutConstraint constant proxies
87 |
88 | - (MASConstraint * (^)(MASEdgeInsets))insets {
89 | return ^id(MASEdgeInsets insets){
90 | self.insets = insets;
91 | return self;
92 | };
93 | }
94 |
95 | - (MASConstraint * (^)(CGSize))sizeOffset {
96 | return ^id(CGSize offset) {
97 | self.sizeOffset = offset;
98 | return self;
99 | };
100 | }
101 |
102 | - (MASConstraint * (^)(CGPoint))centerOffset {
103 | return ^id(CGPoint offset) {
104 | self.centerOffset = offset;
105 | return self;
106 | };
107 | }
108 |
109 | - (MASConstraint * (^)(CGFloat))offset {
110 | return ^id(CGFloat offset){
111 | self.offset = offset;
112 | return self;
113 | };
114 | }
115 |
116 | - (MASConstraint * (^)(NSValue *value))valueOffset {
117 | return ^id(NSValue *offset) {
118 | NSAssert([offset isKindOfClass:NSValue.class], @"expected an NSValue offset, got: %@", offset);
119 | [self setLayoutConstantWithValue:offset];
120 | return self;
121 | };
122 | }
123 |
124 | - (MASConstraint * (^)(id offset))mas_offset {
125 | // Will never be called due to macro
126 | return nil;
127 | }
128 |
129 | #pragma mark - NSLayoutConstraint constant setter
130 |
131 | - (void)setLayoutConstantWithValue:(NSValue *)value {
132 | if ([value isKindOfClass:NSNumber.class]) {
133 | self.offset = [(NSNumber *)value doubleValue];
134 | } else if (strcmp(value.objCType, @encode(CGPoint)) == 0) {
135 | CGPoint point;
136 | [value getValue:&point];
137 | self.centerOffset = point;
138 | } else if (strcmp(value.objCType, @encode(CGSize)) == 0) {
139 | CGSize size;
140 | [value getValue:&size];
141 | self.sizeOffset = size;
142 | } else if (strcmp(value.objCType, @encode(MASEdgeInsets)) == 0) {
143 | MASEdgeInsets insets;
144 | [value getValue:&insets];
145 | self.insets = insets;
146 | } else {
147 | NSAssert(NO, @"attempting to set layout constant with unsupported value: %@", value);
148 | }
149 | }
150 |
151 | #pragma mark - Semantic properties
152 |
153 | - (MASConstraint *)with {
154 | return self;
155 | }
156 |
157 | - (MASConstraint *)and {
158 | return self;
159 | }
160 |
161 | #pragma mark - Chaining
162 |
163 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute __unused)layoutAttribute {
164 | MASMethodNotImplemented();
165 | }
166 |
167 | - (MASConstraint *)left {
168 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft];
169 | }
170 |
171 | - (MASConstraint *)top {
172 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop];
173 | }
174 |
175 | - (MASConstraint *)right {
176 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight];
177 | }
178 |
179 | - (MASConstraint *)bottom {
180 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom];
181 | }
182 |
183 | - (MASConstraint *)leading {
184 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading];
185 | }
186 |
187 | - (MASConstraint *)trailing {
188 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing];
189 | }
190 |
191 | - (MASConstraint *)width {
192 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth];
193 | }
194 |
195 | - (MASConstraint *)height {
196 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight];
197 | }
198 |
199 | - (MASConstraint *)centerX {
200 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX];
201 | }
202 |
203 | - (MASConstraint *)centerY {
204 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY];
205 | }
206 |
207 | - (MASConstraint *)baseline {
208 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline];
209 | }
210 |
211 | #pragma mark - Abstract
212 |
213 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy { MASMethodNotImplemented(); }
214 |
215 | - (MASConstraint * (^)(CGFloat divider))dividedBy { MASMethodNotImplemented(); }
216 |
217 | - (MASConstraint * (^)(MASLayoutPriority priority))priority { MASMethodNotImplemented(); }
218 |
219 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { MASMethodNotImplemented(); }
220 |
221 | - (MASConstraint * (^)(id key))key { MASMethodNotImplemented(); }
222 |
223 | - (void)setInsets:(MASEdgeInsets __unused)insets { MASMethodNotImplemented(); }
224 |
225 | - (void)setSizeOffset:(CGSize __unused)sizeOffset { MASMethodNotImplemented(); }
226 |
227 | - (void)setCenterOffset:(CGPoint __unused)centerOffset { MASMethodNotImplemented(); }
228 |
229 | - (void)setOffset:(CGFloat __unused)offset { MASMethodNotImplemented(); }
230 |
231 | #if TARGET_OS_MAC && !TARGET_OS_IPHONE
232 |
233 | - (MASConstraint *)animator { MASMethodNotImplemented(); }
234 |
235 | #endif
236 |
237 | - (void)install { MASMethodNotImplemented(); }
238 |
239 | - (void)uninstall { MASMethodNotImplemented(); }
240 |
241 | @end
242 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASConstraintMaker.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraintBuilder.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraintMaker.h"
10 | #import "MASViewConstraint.h"
11 | #import "MASCompositeConstraint.h"
12 | #import "MASConstraint+Private.h"
13 | #import "MASViewAttribute.h"
14 | #import "View+MASAdditions.h"
15 |
16 | @interface MASConstraintMaker ()
17 |
18 | @property (nonatomic, weak) MAS_VIEW *view;
19 | @property (nonatomic, strong) NSMutableArray *constraints;
20 |
21 | @end
22 |
23 | @implementation MASConstraintMaker
24 |
25 | - (id)initWithView:(MAS_VIEW *)view {
26 | self = [super init];
27 | if (!self) return nil;
28 |
29 | self.view = view;
30 | self.constraints = NSMutableArray.new;
31 |
32 | return self;
33 | }
34 |
35 | - (NSArray *)install {
36 | if (self.removeExisting) {
37 | NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:self.view];
38 | for (MASConstraint *constraint in installedConstraints) {
39 | [constraint uninstall];
40 | }
41 | }
42 | NSArray *constraints = self.constraints.copy;
43 | for (MASConstraint *constraint in constraints) {
44 | constraint.updateExisting = self.updateExisting;
45 | [constraint install];
46 | }
47 | [self.constraints removeAllObjects];
48 | return constraints;
49 | }
50 |
51 | #pragma mark - MASConstraintDelegate
52 |
53 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint {
54 | NSUInteger index = [self.constraints indexOfObject:constraint];
55 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint);
56 | [self.constraints replaceObjectAtIndex:index withObject:replacementConstraint];
57 | }
58 |
59 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
60 | MASViewAttribute *viewAttribute = [[MASViewAttribute alloc] initWithView:self.view layoutAttribute:layoutAttribute];
61 | MASViewConstraint *newConstraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:viewAttribute];
62 | if ([constraint isKindOfClass:MASViewConstraint.class]) {
63 | //replace with composite constraint
64 | NSArray *children = @[constraint, newConstraint];
65 | MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children];
66 | compositeConstraint.delegate = self;
67 | [self constraint:constraint shouldBeReplacedWithConstraint:compositeConstraint];
68 | return compositeConstraint;
69 | }
70 | if (!constraint) {
71 | newConstraint.delegate = self;
72 | [self.constraints addObject:newConstraint];
73 | }
74 | return newConstraint;
75 | }
76 |
77 | - (MASConstraint *)addConstraintWithAttributes:(MASAttribute)attrs {
78 | MASAttribute anyAttribute = MASAttributeLeft | MASAttributeRight | MASAttributeTop | MASAttributeBottom | MASAttributeLeading | MASAttributeTrailing | MASAttributeWidth | MASAttributeHeight | MASAttributeCenterX | MASAttributeCenterY | MASAttributeBaseline;
79 |
80 | NSAssert((attrs & anyAttribute) != 0, @"You didn't pass any attribute to make.attributes(...)");
81 |
82 | NSMutableArray *attributes = [NSMutableArray array];
83 |
84 | if (attrs & MASAttributeLeft) [attributes addObject:self.view.mas_left];
85 | if (attrs & MASAttributeRight) [attributes addObject:self.view.mas_right];
86 | if (attrs & MASAttributeTop) [attributes addObject:self.view.mas_top];
87 | if (attrs & MASAttributeBottom) [attributes addObject:self.view.mas_bottom];
88 | if (attrs & MASAttributeLeading) [attributes addObject:self.view.mas_leading];
89 | if (attrs & MASAttributeTrailing) [attributes addObject:self.view.mas_trailing];
90 | if (attrs & MASAttributeWidth) [attributes addObject:self.view.mas_width];
91 | if (attrs & MASAttributeHeight) [attributes addObject:self.view.mas_height];
92 | if (attrs & MASAttributeCenterX) [attributes addObject:self.view.mas_centerX];
93 | if (attrs & MASAttributeCenterY) [attributes addObject:self.view.mas_centerY];
94 | if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline];
95 |
96 | NSMutableArray *children = [NSMutableArray arrayWithCapacity:attributes.count];
97 |
98 | for (MASViewAttribute *a in attributes) {
99 | [children addObject:[[MASViewConstraint alloc] initWithFirstViewAttribute:a]];
100 | }
101 |
102 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children];
103 | constraint.delegate = self;
104 | [self.constraints addObject:constraint];
105 | return constraint;
106 | }
107 |
108 | #pragma mark - standard Attributes
109 |
110 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
111 | return [self constraint:nil addConstraintWithLayoutAttribute:layoutAttribute];
112 | }
113 |
114 | - (MASConstraint *)left {
115 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft];
116 | }
117 |
118 | - (MASConstraint *)top {
119 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop];
120 | }
121 |
122 | - (MASConstraint *)right {
123 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight];
124 | }
125 |
126 | - (MASConstraint *)bottom {
127 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom];
128 | }
129 |
130 | - (MASConstraint *)leading {
131 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading];
132 | }
133 |
134 | - (MASConstraint *)trailing {
135 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing];
136 | }
137 |
138 | - (MASConstraint *)width {
139 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth];
140 | }
141 |
142 | - (MASConstraint *)height {
143 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight];
144 | }
145 |
146 | - (MASConstraint *)centerX {
147 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX];
148 | }
149 |
150 | - (MASConstraint *)centerY {
151 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY];
152 | }
153 |
154 | - (MASConstraint *)baseline {
155 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline];
156 | }
157 |
158 | - (MASConstraint *(^)(MASAttribute))attributes {
159 | return ^(MASAttribute attrs){
160 | return [self addConstraintWithAttributes:attrs];
161 | };
162 | }
163 |
164 |
165 | #pragma mark - composite Attributes
166 |
167 | - (MASConstraint *)edges {
168 | return [self addConstraintWithAttributes:MASAttributeTop | MASAttributeLeft | MASAttributeRight | MASAttributeBottom];
169 | }
170 |
171 | - (MASConstraint *)size {
172 | return [self addConstraintWithAttributes:MASAttributeWidth | MASAttributeHeight];
173 | }
174 |
175 | - (MASConstraint *)center {
176 | return [self addConstraintWithAttributes:MASAttributeCenterX | MASAttributeCenterY];
177 | }
178 |
179 | #pragma mark - grouping
180 |
181 | - (MASConstraint *(^)(dispatch_block_t group))group {
182 | return ^id(dispatch_block_t group) {
183 | NSInteger previousCount = self.constraints.count;
184 | group();
185 |
186 | NSArray *children = [self.constraints subarrayWithRange:NSMakeRange(previousCount, self.constraints.count - previousCount)];
187 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children];
188 | constraint.delegate = self;
189 | return constraint;
190 | };
191 | }
192 |
193 | @end
194 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/Masonry/MASViewConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASViewConstraint.h"
10 | #import "MASConstraint+Private.h"
11 | #import "MASCompositeConstraint.h"
12 | #import "MASLayoutConstraint.h"
13 | #import "View+MASAdditions.h"
14 | #import
15 |
16 | @interface MAS_VIEW (MASConstraints)
17 |
18 | @property (nonatomic, readonly) NSMutableSet *mas_installedConstraints;
19 |
20 | @end
21 |
22 | @implementation MAS_VIEW (MASConstraints)
23 |
24 | static char kInstalledConstraintsKey;
25 |
26 | - (NSMutableSet *)mas_installedConstraints {
27 | NSMutableSet *constraints = objc_getAssociatedObject(self, &kInstalledConstraintsKey);
28 | if (!constraints) {
29 | constraints = [NSMutableSet set];
30 | objc_setAssociatedObject(self, &kInstalledConstraintsKey, constraints, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
31 | }
32 | return constraints;
33 | }
34 |
35 | @end
36 |
37 |
38 | @interface MASViewConstraint ()
39 |
40 | @property (nonatomic, strong, readwrite) MASViewAttribute *secondViewAttribute;
41 | @property (nonatomic, weak) MAS_VIEW *installedView;
42 | @property (nonatomic, weak) MASLayoutConstraint *layoutConstraint;
43 | @property (nonatomic, assign) NSLayoutRelation layoutRelation;
44 | @property (nonatomic, assign) MASLayoutPriority layoutPriority;
45 | @property (nonatomic, assign) CGFloat layoutMultiplier;
46 | @property (nonatomic, assign) CGFloat layoutConstant;
47 | @property (nonatomic, assign) BOOL hasLayoutRelation;
48 | @property (nonatomic, strong) id mas_key;
49 | @property (nonatomic, assign) BOOL useAnimator;
50 |
51 | @end
52 |
53 | @implementation MASViewConstraint
54 |
55 | - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute {
56 | self = [super init];
57 | if (!self) return nil;
58 |
59 | _firstViewAttribute = firstViewAttribute;
60 | self.layoutPriority = MASLayoutPriorityRequired;
61 | self.layoutMultiplier = 1;
62 |
63 | return self;
64 | }
65 |
66 | #pragma mark - NSCoping
67 |
68 | - (id)copyWithZone:(NSZone __unused *)zone {
69 | MASViewConstraint *constraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:self.firstViewAttribute];
70 | constraint.layoutConstant = self.layoutConstant;
71 | constraint.layoutRelation = self.layoutRelation;
72 | constraint.layoutPriority = self.layoutPriority;
73 | constraint.layoutMultiplier = self.layoutMultiplier;
74 | constraint.delegate = self.delegate;
75 | return constraint;
76 | }
77 |
78 | #pragma mark - Public
79 |
80 | + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view {
81 | return [view.mas_installedConstraints allObjects];
82 | }
83 |
84 | #pragma mark - Private
85 |
86 | - (void)setLayoutConstant:(CGFloat)layoutConstant {
87 | _layoutConstant = layoutConstant;
88 |
89 | #if TARGET_OS_MAC && !TARGET_OS_IPHONE
90 | if (self.useAnimator) {
91 | [self.layoutConstraint.animator setConstant:layoutConstant];
92 | } else {
93 | self.layoutConstraint.constant = layoutConstant;
94 | }
95 | #else
96 | self.layoutConstraint.constant = layoutConstant;
97 | #endif
98 | }
99 |
100 | - (void)setLayoutRelation:(NSLayoutRelation)layoutRelation {
101 | _layoutRelation = layoutRelation;
102 | self.hasLayoutRelation = YES;
103 | }
104 |
105 | - (BOOL)hasBeenInstalled {
106 | return self.layoutConstraint != nil;
107 | }
108 |
109 | - (void)setSecondViewAttribute:(id)secondViewAttribute {
110 | if ([secondViewAttribute isKindOfClass:NSValue.class]) {
111 | [self setLayoutConstantWithValue:secondViewAttribute];
112 | } else if ([secondViewAttribute isKindOfClass:MAS_VIEW.class]) {
113 | _secondViewAttribute = [[MASViewAttribute alloc] initWithView:secondViewAttribute layoutAttribute:self.firstViewAttribute.layoutAttribute];
114 | } else if ([secondViewAttribute isKindOfClass:MASViewAttribute.class]) {
115 | _secondViewAttribute = secondViewAttribute;
116 | } else {
117 | NSAssert(NO, @"attempting to add unsupported attribute: %@", secondViewAttribute);
118 | }
119 | }
120 |
121 | #pragma mark - NSLayoutConstraint multiplier proxies
122 |
123 | - (MASConstraint * (^)(CGFloat))multipliedBy {
124 | return ^id(CGFloat multiplier) {
125 | NSAssert(!self.hasBeenInstalled,
126 | @"Cannot modify constraint multiplier after it has been installed");
127 |
128 | self.layoutMultiplier = multiplier;
129 | return self;
130 | };
131 | }
132 |
133 |
134 | - (MASConstraint * (^)(CGFloat))dividedBy {
135 | return ^id(CGFloat divider) {
136 | NSAssert(!self.hasBeenInstalled,
137 | @"Cannot modify constraint multiplier after it has been installed");
138 |
139 | self.layoutMultiplier = 1.0/divider;
140 | return self;
141 | };
142 | }
143 |
144 | #pragma mark - MASLayoutPriority proxy
145 |
146 | - (MASConstraint * (^)(MASLayoutPriority))priority {
147 | return ^id(MASLayoutPriority priority) {
148 | NSAssert(!self.hasBeenInstalled,
149 | @"Cannot modify constraint priority after it has been installed");
150 |
151 | self.layoutPriority = priority;
152 | return self;
153 | };
154 | }
155 |
156 | #pragma mark - NSLayoutRelation proxy
157 |
158 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation {
159 | return ^id(id attribute, NSLayoutRelation relation) {
160 | if ([attribute isKindOfClass:NSArray.class]) {
161 | NSAssert(!self.hasLayoutRelation, @"Redefinition of constraint relation");
162 | NSMutableArray *children = NSMutableArray.new;
163 | for (id attr in attribute) {
164 | MASViewConstraint *viewConstraint = [self copy];
165 | viewConstraint.secondViewAttribute = attr;
166 | [children addObject:viewConstraint];
167 | }
168 | MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children];
169 | compositeConstraint.delegate = self.delegate;
170 | [self.delegate constraint:self shouldBeReplacedWithConstraint:compositeConstraint];
171 | return compositeConstraint;
172 | } else {
173 | NSAssert(!self.hasLayoutRelation || self.layoutRelation == relation && [attribute isKindOfClass:NSValue.class], @"Redefinition of constraint relation");
174 | self.layoutRelation = relation;
175 | self.secondViewAttribute = attribute;
176 | return self;
177 | }
178 | };
179 | }
180 |
181 | #pragma mark - Semantic properties
182 |
183 | - (MASConstraint *)with {
184 | return self;
185 | }
186 |
187 | - (MASConstraint *)and {
188 | return self;
189 | }
190 |
191 | #pragma mark - attribute chaining
192 |
193 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
194 | NSAssert(!self.hasLayoutRelation, @"Attributes should be chained before defining the constraint relation");
195 |
196 | return [self.delegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
197 | }
198 |
199 | #pragma mark - Animator proxy
200 |
201 | #if TARGET_OS_MAC && !TARGET_OS_IPHONE
202 |
203 | - (MASConstraint *)animator {
204 | self.useAnimator = YES;
205 | return self;
206 | }
207 |
208 | #endif
209 |
210 | #pragma mark - debug helpers
211 |
212 | - (MASConstraint * (^)(id))key {
213 | return ^id(id key) {
214 | self.mas_key = key;
215 | return self;
216 | };
217 | }
218 |
219 | #pragma mark - NSLayoutConstraint constant setters
220 |
221 | - (void)setInsets:(MASEdgeInsets)insets {
222 | NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
223 | switch (layoutAttribute) {
224 | case NSLayoutAttributeLeft:
225 | self.layoutConstant = insets.left;
226 | break;
227 | case NSLayoutAttributeTop:
228 | self.layoutConstant = insets.top;
229 | break;
230 | case NSLayoutAttributeBottom:
231 | self.layoutConstant = -insets.bottom;
232 | break;
233 | case NSLayoutAttributeRight:
234 | self.layoutConstant = -insets.right;
235 | break;
236 | default:
237 | break;
238 | }
239 | }
240 |
241 | - (void)setOffset:(CGFloat)offset {
242 | self.layoutConstant = offset;
243 | }
244 |
245 | - (void)setSizeOffset:(CGSize)sizeOffset {
246 | NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
247 | switch (layoutAttribute) {
248 | case NSLayoutAttributeWidth:
249 | self.layoutConstant = sizeOffset.width;
250 | break;
251 | case NSLayoutAttributeHeight:
252 | self.layoutConstant = sizeOffset.height;
253 | break;
254 | default:
255 | break;
256 | }
257 | }
258 |
259 | - (void)setCenterOffset:(CGPoint)centerOffset {
260 | NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
261 | switch (layoutAttribute) {
262 | case NSLayoutAttributeCenterX:
263 | self.layoutConstant = centerOffset.x;
264 | break;
265 | case NSLayoutAttributeCenterY:
266 | self.layoutConstant = centerOffset.y;
267 | break;
268 | default:
269 | break;
270 | }
271 | }
272 |
273 | #pragma mark - MASConstraint
274 |
275 | - (void)install {
276 | NSAssert(!self.hasBeenInstalled, @"Cannot install constraint more than once");
277 |
278 | MAS_VIEW *firstLayoutItem = self.firstViewAttribute.view;
279 | NSLayoutAttribute firstLayoutAttribute = self.firstViewAttribute.layoutAttribute;
280 | MAS_VIEW *secondLayoutItem = self.secondViewAttribute.view;
281 | NSLayoutAttribute secondLayoutAttribute = self.secondViewAttribute.layoutAttribute;
282 |
283 | // alignment attributes must have a secondViewAttribute
284 | // therefore we assume that is refering to superview
285 | // eg make.left.equalTo(@10)
286 | if (!self.firstViewAttribute.isSizeAttribute && !self.secondViewAttribute) {
287 | secondLayoutItem = firstLayoutItem.superview;
288 | secondLayoutAttribute = firstLayoutAttribute;
289 | }
290 |
291 | MASLayoutConstraint *layoutConstraint
292 | = [MASLayoutConstraint constraintWithItem:firstLayoutItem
293 | attribute:firstLayoutAttribute
294 | relatedBy:self.layoutRelation
295 | toItem:secondLayoutItem
296 | attribute:secondLayoutAttribute
297 | multiplier:self.layoutMultiplier
298 | constant:self.layoutConstant];
299 |
300 | layoutConstraint.priority = self.layoutPriority;
301 | layoutConstraint.mas_key = self.mas_key;
302 |
303 | if (secondLayoutItem) {
304 | MAS_VIEW *closestCommonSuperview = [firstLayoutItem mas_closestCommonSuperview:secondLayoutItem];
305 | NSAssert(closestCommonSuperview,
306 | @"couldn't find a common superview for %@ and %@",
307 | firstLayoutItem, secondLayoutItem);
308 | self.installedView = closestCommonSuperview;
309 | } else {
310 | self.installedView = firstLayoutItem;
311 | }
312 |
313 |
314 | MASLayoutConstraint *existingConstraint = nil;
315 | if (self.updateExisting) {
316 | existingConstraint = [self layoutConstraintSimilarTo:layoutConstraint];
317 | }
318 | if (existingConstraint) {
319 | // just update the constant
320 | existingConstraint.constant = layoutConstraint.constant;
321 | self.layoutConstraint = existingConstraint;
322 | } else {
323 | [self.installedView addConstraint:layoutConstraint];
324 | self.layoutConstraint = layoutConstraint;
325 | }
326 |
327 | [firstLayoutItem.mas_installedConstraints addObject:self];
328 | }
329 |
330 | - (MASLayoutConstraint *)layoutConstraintSimilarTo:(MASLayoutConstraint *)layoutConstraint {
331 | // check if any constraints are the same apart from the only mutable property constant
332 |
333 | // go through constraints in reverse as we do not want to match auto-resizing or interface builder constraints
334 | // and they are likely to be added first.
335 | for (NSLayoutConstraint *existingConstraint in self.installedView.constraints.reverseObjectEnumerator) {
336 | if (![existingConstraint isKindOfClass:MASLayoutConstraint.class]) continue;
337 | if (existingConstraint.firstItem != layoutConstraint.firstItem) continue;
338 | if (existingConstraint.secondItem != layoutConstraint.secondItem) continue;
339 | if (existingConstraint.firstAttribute != layoutConstraint.firstAttribute) continue;
340 | if (existingConstraint.secondAttribute != layoutConstraint.secondAttribute) continue;
341 | if (existingConstraint.relation != layoutConstraint.relation) continue;
342 | if (existingConstraint.multiplier != layoutConstraint.multiplier) continue;
343 | if (existingConstraint.priority != layoutConstraint.priority) continue;
344 |
345 | return (id)existingConstraint;
346 | }
347 | return nil;
348 | }
349 |
350 | - (void)uninstall {
351 | [self.installedView removeConstraint:self.layoutConstraint];
352 | self.layoutConstraint = nil;
353 | self.installedView = nil;
354 | [self.firstViewAttribute.view.mas_installedConstraints removeObject:self];
355 | }
356 |
357 | @end
358 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/controllers/AutoResizeCellController.m:
--------------------------------------------------------------------------------
1 | //
2 | // AutoResizeCellController.m
3 | // AutoResizeCellDemo
4 | //
5 | // Created by Aevitx on 14/12/3.
6 | // Copyright (c) 2014年 Aevit. All rights reserved.
7 | //
8 |
9 | #import "AutoResizeCellController.h"
10 | #import "SVProgressHUD.h"
11 | #import "AutoResizeCell.h"
12 | #import "SecondResizeCell.h"
13 | #import "Masonry.h"
14 |
15 | #define SWITCH_SIMPLE_DEMO 1
16 |
17 | #define HAS_AVATAR @"hasAvatar"
18 | #define ROW_DATA_KEY @"rowDataKey"
19 |
20 | static NSString *autoResizeCellId = @"autoResizeCellId";
21 | static NSString *secondResizeCellId = @"secondResizeCellId";
22 |
23 |
24 | @interface AutoResizeCellController ()
25 |
26 | @property (nonatomic, strong) UITableView *myTableView;
27 | @property (nonatomic, strong) NSMutableArray *dataArray;
28 | @property (nonatomic, strong) NSMutableDictionary *offscreenCell;
29 |
30 | @property (nonatomic, assign) BOOL isInsertACellOnTop;
31 |
32 | @end
33 |
34 | @implementation AutoResizeCellController
35 |
36 | - (void)viewDidLoad {
37 | [super viewDidLoad];
38 | // Do any additional setup after loading the view.
39 |
40 | self.title = @"auto resize cell";
41 |
42 | self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStylePlain target:self action:@selector(backBtnPressed:)];
43 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"options" style:UIBarButtonItemStylePlain target:self action:@selector(optionsBtnPressed:)];
44 |
45 | self.isInsertACellOnTop = NO;
46 |
47 | [self generateDataArrayWithSectionNum:2 rowNum:2];
48 |
49 | UITableView *aTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
50 | aTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
51 | aTable.delegate = self;
52 | aTable.dataSource = self;
53 | [self.view addSubview:aTable];
54 | self.myTableView = aTable;
55 |
56 | [aTable mas_makeConstraints:^(MASConstraintMaker *make) {
57 | make.edges.mas_equalTo(self.view);
58 | }];
59 |
60 | /////////////// step: 1 ///////////////
61 | self.offscreenCell = [NSMutableDictionary dictionary];
62 | /////////////// step: 1 ///////////////
63 |
64 | /////////////// step: 2 ///////////////
65 | [self.myTableView registerClass:[AutoResizeCell class] forCellReuseIdentifier:autoResizeCellId];
66 | [self.myTableView registerClass:[SecondResizeCell class] forCellReuseIdentifier:secondResizeCellId];
67 | // Setting the estimated row height prevents the table view from calling tableView:heightForRowAtIndexPath: for every row in the table on first load;
68 | // it will only be called as cells are about to scroll onscreen. This is a major performance optimization.
69 | self.myTableView.estimatedRowHeight = UITableViewAutomaticDimension; // iOS7+
70 | /////////////// step: 2 ///////////////
71 | }
72 |
73 | - (void)didReceiveMemoryWarning {
74 | [super didReceiveMemoryWarning];
75 | // Dispose of any resources that can be recreated.
76 | }
77 |
78 | #pragma mark - private
79 | + (NSString *)randomStringOfMaxLength:(int)maxLength {
80 | static NSString *characters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
81 |
82 | int length = arc4random_uniform(maxLength);
83 | NSMutableString *randomString = [NSMutableString stringWithCapacity:length];
84 | for (int i=0; i 0 ? [self getRowDataArrInSection:0] : [NSMutableArray array]);
105 | int rowCount = 0;
106 | for (NSInteger j = 0; j < rowNum; j++) {
107 | NSDictionary *rowDict = @{
108 | HAS_AVATAR: @(arc4random() % 2),
109 | @"title": [NSString stringWithFormat:@"%d: %@", rowCount,[AutoResizeCellController randomStringOfMaxLength:50]],
110 | @"content": [AutoResizeCellController randomStringOfMaxLength:200]
111 | };
112 | rowCount++;
113 | [rowArr insertObject:rowDict atIndex:0];
114 | }
115 |
116 | NSDictionary *sectionDict = @{@"sectionTitle": [NSString stringWithFormat:@"The %d section", sectionCount],
117 | ROW_DATA_KEY: rowArr
118 | };
119 | sectionCount++;
120 | if (self.isInsertACellOnTop && [_dataArray count] > 0) {
121 | [_dataArray replaceObjectAtIndex:0 withObject:sectionDict];
122 | } else {
123 | [_dataArray insertObject:sectionDict atIndex:0];
124 | }
125 | }
126 | }
127 |
128 | #pragma mark - actions
129 | - (void)backBtnPressed:(id)sender {
130 | [self.navigationController dismissViewControllerAnimated:YES completion:^{}];
131 | }
132 |
133 | - (void)optionsBtnPressed:(id)sender {
134 | UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"choose" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:nil otherButtonTitles:
135 | #if !SWITCH_SIMPLE_DEMO
136 | @"delete all",
137 | @"delete first cell",
138 | @"delete first section",
139 | @"insert a cell on top",
140 | @"insert a section on top",
141 | @"reGet data for one section",
142 | @"reGet data for multi sections",
143 | #endif
144 | @"change the text for the first cell",
145 | @"change the text for the first section", nil];
146 | [as showInView:self.view];
147 | }
148 |
149 | #pragma mark - actionsheet
150 | - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
151 | if (buttonIndex == actionSheet.cancelButtonIndex) {
152 | return;
153 | }
154 | self.isInsertACellOnTop = NO;
155 | switch (buttonIndex) {
156 | #if SWITCH_SIMPLE_DEMO
157 | case 0:
158 | {
159 | // change the text for the first cell
160 | [self changeTheTextOfTheFirstCell];
161 | break;
162 | }
163 | case 1:
164 | {
165 | // change the text for the first section
166 | [self changeTheTextOfTheFirstSection];
167 | break;
168 | }
169 | #else
170 | case 0:
171 | {
172 | // delete all
173 | NSInteger dataCount = [self.dataArray count];
174 | [self.dataArray removeAllObjects];
175 | [self.myTableView beginUpdates];
176 | [self.myTableView deleteSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, dataCount)] withRowAnimation:UITableViewRowAnimationFade];
177 | [self.myTableView endUpdates];
178 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
179 | [SVProgressHUD showSuccessWithStatus:@"Thanks"];
180 | });
181 | break;
182 | }
183 | case 1:
184 | {
185 | // delete first cell
186 | if ([self.dataArray count] <= 0) {
187 | [SVProgressHUD showErrorWithStatus:@"the section num is 0"];
188 | return;
189 | }
190 | if ([[self getRowDataArrInSection:0] count] <= 0) {
191 | [SVProgressHUD showErrorWithStatus:@"the row num of the first section is 0"];
192 | return;
193 | }
194 | [[self getRowDataArrInSection:0] removeObjectAtIndex:0];
195 | [self.myTableView beginUpdates];
196 | [self.myTableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
197 | [self.myTableView endUpdates];
198 | break;
199 | }
200 | case 2:
201 | {
202 | // delete first section
203 | if ([_dataArray count] <= 0) {
204 | [SVProgressHUD showErrorWithStatus:@"the section num is 0"];
205 | return;
206 | }
207 | [self.dataArray removeObjectAtIndex:0];
208 | [self.myTableView beginUpdates];
209 | [self.myTableView deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
210 | [self.myTableView endUpdates];
211 | break;
212 | }
213 | case 3:
214 | {
215 | // insert a cell on the top
216 | self.isInsertACellOnTop = YES;
217 | BOOL hasAtLeastOneSection = ([self.dataArray count] > 0 ? YES : NO);
218 | [self generateDataArrayWithRowNum:1];
219 | [self.myTableView beginUpdates];
220 | if (hasAtLeastOneSection) {
221 | [self.myTableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
222 | } else {
223 | [self.myTableView insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
224 | }
225 | [self.myTableView endUpdates];
226 | break;
227 | }
228 | case 4:
229 | {
230 | // insert a section on the top
231 | [self generateDataArrayWithSectionNum:1 rowNum:3];
232 | [self.myTableView insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
233 | [self.myTableView endUpdates];
234 | break;
235 | }
236 | case 5:
237 | {
238 | // reGet data for one section
239 | [self.dataArray removeAllObjects];
240 | [self generateDataArrayWithRowNum:arc4random() % 100];
241 | [self.myTableView reloadData];
242 | break;
243 | }
244 | case 6:
245 | {
246 | // reGet data for multi sections
247 | [self.dataArray removeAllObjects];
248 | [self generateDataArrayWithSectionNum:(arc4random() % 5) rowNum:(arc4random() % 50)];
249 | [self.myTableView reloadData];
250 | break;
251 | }
252 | case 7:
253 | {
254 | // change the text for the first cell
255 | [self changeTheTextOfTheFirstCell];
256 | break;
257 | }
258 | case 8:
259 | {
260 | // change the text for the first section
261 | [self changeTheTextOfTheFirstSection];
262 | break;
263 | }
264 | #endif
265 | default:
266 | break;
267 | }
268 | }
269 |
270 | // change the text for the first cell
271 | - (void)changeTheTextOfTheFirstCell {
272 | if ([self.dataArray count] <= 0) {
273 | [SVProgressHUD showErrorWithStatus:@"the section num is 0"];
274 | return;
275 | }
276 | if ([[self getRowDataArrInSection:0] count] <= 0) {
277 | [SVProgressHUD showErrorWithStatus:@"the row num of the first section is 0"];
278 | return;
279 | }
280 | NSMutableDictionary *aDict = [NSMutableDictionary dictionaryWithDictionary:[self getRowDataDictInSection:0 row:0]];
281 | [aDict setObject:[AutoResizeCellController randomStringOfMaxLength:50] forKey:@"title"];
282 | [aDict setObject:[AutoResizeCellController randomStringOfMaxLength:200] forKey:@"content"];
283 | [[self getRowDataArrInSection:0] replaceObjectAtIndex:0 withObject:aDict];
284 | [self.myTableView beginUpdates];
285 | [self.myTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
286 | [self.myTableView endUpdates];
287 | }
288 |
289 | // change the text for the first section
290 | - (void)changeTheTextOfTheFirstSection {
291 | if ([self.dataArray count] <= 0) {
292 | [SVProgressHUD showErrorWithStatus:@"the section num is 0"];
293 | return;
294 | }
295 | NSInteger firstSectionCount = [[self getRowDataArrInSection:0] count];
296 | [self.dataArray removeObjectAtIndex:0];
297 | [self generateDataArrayWithSectionNum:1 rowNum:firstSectionCount];
298 | [self.myTableView beginUpdates];
299 | [self.myTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
300 | [self.myTableView endUpdates];
301 | }
302 |
303 | #pragma mark - get data
304 | - (NSDictionary*)getSectionDataDictInSection:(NSInteger)section {
305 | return _dataArray[section];
306 | }
307 |
308 | - (NSMutableArray*)getRowDataArrInSection:(NSInteger)section {
309 | return [_dataArray[section] objectForKey:ROW_DATA_KEY];
310 | }
311 |
312 | - (NSDictionary*)getRowDataDictInSection:(NSInteger)section row:(NSInteger)row {
313 | return [self getRowDataArrInSection:section][row];
314 | }
315 |
316 | #pragma mark - tableview
317 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
318 | return [[self getRowDataArrInSection:section] count];
319 | }
320 |
321 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
322 | return [_dataArray count];
323 | }
324 |
325 | - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
326 | return 20;
327 | }
328 |
329 | - (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
330 | return [[self getSectionDataDictInSection:section] objectForKey:@"sectionTitle"];
331 | }
332 |
333 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
334 |
335 | /////////////// step: 3 ///////////////
336 | NSDictionary *aDict = [self getRowDataDictInSection:indexPath.section row:indexPath.row];
337 | BOOL hasAvatar = [[aDict objectForKey:HAS_AVATAR] boolValue];
338 | NSString *reuseIdentifier = (hasAvatar ? secondResizeCellId : autoResizeCellId);
339 | UITableViewCell *cell = [self.offscreenCell objectForKey:reuseIdentifier];
340 | if (!cell) {
341 | if (hasAvatar) {
342 | cell = [[SecondResizeCell alloc] init];
343 | } else {
344 | cell = [[AutoResizeCell alloc] init];
345 | }
346 | [self.offscreenCell setObject:cell forKey:reuseIdentifier];
347 | }
348 | if (hasAvatar) {
349 | [(SecondResizeCell*)cell initModel:aDict];
350 | } else {
351 | [(AutoResizeCell*)cell initModel:aDict];
352 | }
353 | cell.bounds = CGRectMake(0.0f, 0.0f, CGRectGetWidth(tableView.bounds), CGRectGetHeight(cell.bounds));
354 | [cell setNeedsLayout];
355 | [cell layoutIfNeeded];
356 |
357 | CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
358 | height += 1;
359 | /////////////// step: 3 ///////////////
360 |
361 | return height;
362 | }
363 |
364 | - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
365 |
366 | /////////////// step: 4 ///////////////
367 | NSDictionary *aDict = [self getRowDataDictInSection:indexPath.section row:indexPath.row];
368 | BOOL hasAvatar = [[aDict objectForKey:HAS_AVATAR] boolValue];
369 | NSString *reuseIdentifier = (hasAvatar ? secondResizeCellId : autoResizeCellId);
370 | AutoResizeCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
371 | if (hasAvatar) {
372 | [(SecondResizeCell*)cell initModel:aDict];
373 | } else {
374 | [(AutoResizeCell*)cell initModel:aDict];
375 | }
376 | /////////////// step: 4 ///////////////
377 | return cell;
378 | }
379 |
380 | /*
381 | #pragma mark - Navigation
382 |
383 | // In a storyboard-based application, you will often want to do a little preparation before navigation
384 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
385 | // Get the new view controller using [segue destinationViewController].
386 | // Pass the selected object to the new view controller.
387 | }
388 | */
389 |
390 | @end
391 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | E1B31A371A2F43B5009E22F5 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A361A2F43B5009E22F5 /* main.m */; };
11 | E1B31A3A1A2F43B5009E22F5 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A391A2F43B5009E22F5 /* AppDelegate.m */; };
12 | E1B31A3D1A2F43B5009E22F5 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A3C1A2F43B5009E22F5 /* ViewController.m */; };
13 | E1B31A401A2F43B5009E22F5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E1B31A3E1A2F43B5009E22F5 /* Main.storyboard */; };
14 | E1B31A421A2F43B5009E22F5 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E1B31A411A2F43B5009E22F5 /* Images.xcassets */; };
15 | E1B31A451A2F43B5009E22F5 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = E1B31A431A2F43B5009E22F5 /* LaunchScreen.xib */; };
16 | E1B31A511A2F43B5009E22F5 /* AutoResizeCellDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A501A2F43B5009E22F5 /* AutoResizeCellDemoTests.m */; };
17 | E1B31A5C1A2F46BB009E22F5 /* AutoResizeCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A5B1A2F46BB009E22F5 /* AutoResizeCell.m */; };
18 | E1B31A7A1A2F481A009E22F5 /* UIView+AverageRange.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A621A2F481A009E22F5 /* UIView+AverageRange.m */; };
19 | E1B31A7B1A2F481A009E22F5 /* MASCompositeConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A641A2F481A009E22F5 /* MASCompositeConstraint.m */; };
20 | E1B31A7C1A2F481A009E22F5 /* MASConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A671A2F481A009E22F5 /* MASConstraint.m */; };
21 | E1B31A7D1A2F481A009E22F5 /* MASConstraintMaker.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A691A2F481A009E22F5 /* MASConstraintMaker.m */; };
22 | E1B31A7E1A2F481A009E22F5 /* MASLayoutConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A6B1A2F481A009E22F5 /* MASLayoutConstraint.m */; };
23 | E1B31A7F1A2F481A009E22F5 /* MASViewAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A6F1A2F481A009E22F5 /* MASViewAttribute.m */; };
24 | E1B31A801A2F481A009E22F5 /* MASViewConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A711A2F481A009E22F5 /* MASViewConstraint.m */; };
25 | E1B31A811A2F481A009E22F5 /* NSArray+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A731A2F481A009E22F5 /* NSArray+MASAdditions.m */; };
26 | E1B31A821A2F481A009E22F5 /* NSLayoutConstraint+MASDebugAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A761A2F481A009E22F5 /* NSLayoutConstraint+MASDebugAdditions.m */; };
27 | E1B31A831A2F481A009E22F5 /* View+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A781A2F481A009E22F5 /* View+MASAdditions.m */; };
28 | E1B31A871A2F4E74009E22F5 /* AutoResizeCellController.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B31A861A2F4E74009E22F5 /* AutoResizeCellController.m */; };
29 | E1B606501A3967190070859F /* SecondResizeCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B6064F1A3967190070859F /* SecondResizeCell.m */; };
30 | E1B606551A396B220070859F /* avatar.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = E1B606521A396B220070859F /* avatar.jpeg */; };
31 | E1B606561A396B220070859F /* avatar@2x.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = E1B606531A396B220070859F /* avatar@2x.jpeg */; };
32 | E1B606571A396B220070859F /* avatar@3x.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = E1B606541A396B220070859F /* avatar@3x.jpeg */; };
33 | E1B6065C1A3970D10070859F /* SVProgressHUD.bundle in Resources */ = {isa = PBXBuildFile; fileRef = E1B606591A3970D00070859F /* SVProgressHUD.bundle */; };
34 | E1B6065D1A3970D10070859F /* SVProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B6065B1A3970D10070859F /* SVProgressHUD.m */; };
35 | /* End PBXBuildFile section */
36 |
37 | /* Begin PBXContainerItemProxy section */
38 | E1B31A4B1A2F43B5009E22F5 /* PBXContainerItemProxy */ = {
39 | isa = PBXContainerItemProxy;
40 | containerPortal = E1B31A291A2F43B5009E22F5 /* Project object */;
41 | proxyType = 1;
42 | remoteGlobalIDString = E1B31A301A2F43B5009E22F5;
43 | remoteInfo = AutoResizeCellDemo;
44 | };
45 | /* End PBXContainerItemProxy section */
46 |
47 | /* Begin PBXFileReference section */
48 | E1B31A311A2F43B5009E22F5 /* AutoResizeCellDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AutoResizeCellDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
49 | E1B31A351A2F43B5009E22F5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
50 | E1B31A361A2F43B5009E22F5 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
51 | E1B31A381A2F43B5009E22F5 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
52 | E1B31A391A2F43B5009E22F5 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
53 | E1B31A3B1A2F43B5009E22F5 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; };
54 | E1B31A3C1A2F43B5009E22F5 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; };
55 | E1B31A3F1A2F43B5009E22F5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
56 | E1B31A411A2F43B5009E22F5 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; };
57 | E1B31A441A2F43B5009E22F5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; };
58 | E1B31A4A1A2F43B5009E22F5 /* AutoResizeCellDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AutoResizeCellDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
59 | E1B31A4F1A2F43B5009E22F5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
60 | E1B31A501A2F43B5009E22F5 /* AutoResizeCellDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AutoResizeCellDemoTests.m; sourceTree = ""; };
61 | E1B31A5A1A2F46BB009E22F5 /* AutoResizeCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AutoResizeCell.h; path = views/AutoResizeCell.h; sourceTree = ""; };
62 | E1B31A5B1A2F46BB009E22F5 /* AutoResizeCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AutoResizeCell.m; path = views/AutoResizeCell.m; sourceTree = ""; };
63 | E1B31A611A2F481A009E22F5 /* UIView+AverageRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+AverageRange.h"; sourceTree = ""; };
64 | E1B31A621A2F481A009E22F5 /* UIView+AverageRange.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+AverageRange.m"; sourceTree = ""; };
65 | E1B31A631A2F481A009E22F5 /* MASCompositeConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASCompositeConstraint.h; sourceTree = ""; };
66 | E1B31A641A2F481A009E22F5 /* MASCompositeConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASCompositeConstraint.m; sourceTree = ""; };
67 | E1B31A651A2F481A009E22F5 /* MASConstraint+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MASConstraint+Private.h"; sourceTree = ""; };
68 | E1B31A661A2F481A009E22F5 /* MASConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASConstraint.h; sourceTree = ""; };
69 | E1B31A671A2F481A009E22F5 /* MASConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASConstraint.m; sourceTree = ""; };
70 | E1B31A681A2F481A009E22F5 /* MASConstraintMaker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASConstraintMaker.h; sourceTree = ""; };
71 | E1B31A691A2F481A009E22F5 /* MASConstraintMaker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASConstraintMaker.m; sourceTree = ""; };
72 | E1B31A6A1A2F481A009E22F5 /* MASLayoutConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASLayoutConstraint.h; sourceTree = ""; };
73 | E1B31A6B1A2F481A009E22F5 /* MASLayoutConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASLayoutConstraint.m; sourceTree = ""; };
74 | E1B31A6C1A2F481A009E22F5 /* Masonry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Masonry.h; sourceTree = ""; };
75 | E1B31A6D1A2F481A009E22F5 /* MASUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASUtilities.h; sourceTree = ""; };
76 | E1B31A6E1A2F481A009E22F5 /* MASViewAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASViewAttribute.h; sourceTree = ""; };
77 | E1B31A6F1A2F481A009E22F5 /* MASViewAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASViewAttribute.m; sourceTree = ""; };
78 | E1B31A701A2F481A009E22F5 /* MASViewConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASViewConstraint.h; sourceTree = ""; };
79 | E1B31A711A2F481A009E22F5 /* MASViewConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASViewConstraint.m; sourceTree = ""; };
80 | E1B31A721A2F481A009E22F5 /* NSArray+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+MASAdditions.h"; sourceTree = ""; };
81 | E1B31A731A2F481A009E22F5 /* NSArray+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+MASAdditions.m"; sourceTree = ""; };
82 | E1B31A741A2F481A009E22F5 /* NSArray+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+MASShorthandAdditions.h"; sourceTree = ""; };
83 | E1B31A751A2F481A009E22F5 /* NSLayoutConstraint+MASDebugAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSLayoutConstraint+MASDebugAdditions.h"; sourceTree = ""; };
84 | E1B31A761A2F481A009E22F5 /* NSLayoutConstraint+MASDebugAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSLayoutConstraint+MASDebugAdditions.m"; sourceTree = ""; };
85 | E1B31A771A2F481A009E22F5 /* View+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "View+MASAdditions.h"; sourceTree = ""; };
86 | E1B31A781A2F481A009E22F5 /* View+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "View+MASAdditions.m"; sourceTree = ""; };
87 | E1B31A791A2F481A009E22F5 /* View+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "View+MASShorthandAdditions.h"; sourceTree = ""; };
88 | E1B31A851A2F4E74009E22F5 /* AutoResizeCellController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AutoResizeCellController.h; path = controllers/AutoResizeCellController.h; sourceTree = ""; };
89 | E1B31A861A2F4E74009E22F5 /* AutoResizeCellController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AutoResizeCellController.m; path = controllers/AutoResizeCellController.m; sourceTree = ""; };
90 | E1B6064E1A3967190070859F /* SecondResizeCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SecondResizeCell.h; path = views/SecondResizeCell.h; sourceTree = ""; };
91 | E1B6064F1A3967190070859F /* SecondResizeCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SecondResizeCell.m; path = views/SecondResizeCell.m; sourceTree = ""; };
92 | E1B606521A396B220070859F /* avatar.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = avatar.jpeg; sourceTree = ""; };
93 | E1B606531A396B220070859F /* avatar@2x.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "avatar@2x.jpeg"; sourceTree = ""; };
94 | E1B606541A396B220070859F /* avatar@3x.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "avatar@3x.jpeg"; sourceTree = ""; };
95 | E1B606591A3970D00070859F /* SVProgressHUD.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = SVProgressHUD.bundle; sourceTree = ""; };
96 | E1B6065A1A3970D10070859F /* SVProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVProgressHUD.h; sourceTree = ""; };
97 | E1B6065B1A3970D10070859F /* SVProgressHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVProgressHUD.m; sourceTree = ""; };
98 | /* End PBXFileReference section */
99 |
100 | /* Begin PBXFrameworksBuildPhase section */
101 | E1B31A2E1A2F43B5009E22F5 /* Frameworks */ = {
102 | isa = PBXFrameworksBuildPhase;
103 | buildActionMask = 2147483647;
104 | files = (
105 | );
106 | runOnlyForDeploymentPostprocessing = 0;
107 | };
108 | E1B31A471A2F43B5009E22F5 /* Frameworks */ = {
109 | isa = PBXFrameworksBuildPhase;
110 | buildActionMask = 2147483647;
111 | files = (
112 | );
113 | runOnlyForDeploymentPostprocessing = 0;
114 | };
115 | /* End PBXFrameworksBuildPhase section */
116 |
117 | /* Begin PBXGroup section */
118 | E1B31A281A2F43B5009E22F5 = {
119 | isa = PBXGroup;
120 | children = (
121 | E1B31A331A2F43B5009E22F5 /* AutoResizeCellDemo */,
122 | E1B31A4D1A2F43B5009E22F5 /* AutoResizeCellDemoTests */,
123 | E1B31A321A2F43B5009E22F5 /* Products */,
124 | );
125 | sourceTree = "";
126 | };
127 | E1B31A321A2F43B5009E22F5 /* Products */ = {
128 | isa = PBXGroup;
129 | children = (
130 | E1B31A311A2F43B5009E22F5 /* AutoResizeCellDemo.app */,
131 | E1B31A4A1A2F43B5009E22F5 /* AutoResizeCellDemoTests.xctest */,
132 | );
133 | name = Products;
134 | sourceTree = "";
135 | };
136 | E1B31A331A2F43B5009E22F5 /* AutoResizeCellDemo */ = {
137 | isa = PBXGroup;
138 | children = (
139 | E1B31A381A2F43B5009E22F5 /* AppDelegate.h */,
140 | E1B31A391A2F43B5009E22F5 /* AppDelegate.m */,
141 | E1B31A3B1A2F43B5009E22F5 /* ViewController.h */,
142 | E1B31A3C1A2F43B5009E22F5 /* ViewController.m */,
143 | E1B31A5E1A2F481A009E22F5 /* vendor */,
144 | E1B31A841A2F4E48009E22F5 /* controllers */,
145 | E1B31A5D1A2F46BF009E22F5 /* views */,
146 | E1B31A3E1A2F43B5009E22F5 /* Main.storyboard */,
147 | E1B31A411A2F43B5009E22F5 /* Images.xcassets */,
148 | E1B31A431A2F43B5009E22F5 /* LaunchScreen.xib */,
149 | E1B31A341A2F43B5009E22F5 /* Supporting Files */,
150 | );
151 | path = AutoResizeCellDemo;
152 | sourceTree = "";
153 | };
154 | E1B31A341A2F43B5009E22F5 /* Supporting Files */ = {
155 | isa = PBXGroup;
156 | children = (
157 | E1B606511A396B220070859F /* images */,
158 | E1B31A351A2F43B5009E22F5 /* Info.plist */,
159 | E1B31A361A2F43B5009E22F5 /* main.m */,
160 | );
161 | name = "Supporting Files";
162 | sourceTree = "";
163 | };
164 | E1B31A4D1A2F43B5009E22F5 /* AutoResizeCellDemoTests */ = {
165 | isa = PBXGroup;
166 | children = (
167 | E1B31A501A2F43B5009E22F5 /* AutoResizeCellDemoTests.m */,
168 | E1B31A4E1A2F43B5009E22F5 /* Supporting Files */,
169 | );
170 | path = AutoResizeCellDemoTests;
171 | sourceTree = "";
172 | };
173 | E1B31A4E1A2F43B5009E22F5 /* Supporting Files */ = {
174 | isa = PBXGroup;
175 | children = (
176 | E1B31A4F1A2F43B5009E22F5 /* Info.plist */,
177 | );
178 | name = "Supporting Files";
179 | sourceTree = "";
180 | };
181 | E1B31A5D1A2F46BF009E22F5 /* views */ = {
182 | isa = PBXGroup;
183 | children = (
184 | E1B31A5A1A2F46BB009E22F5 /* AutoResizeCell.h */,
185 | E1B31A5B1A2F46BB009E22F5 /* AutoResizeCell.m */,
186 | E1B6064E1A3967190070859F /* SecondResizeCell.h */,
187 | E1B6064F1A3967190070859F /* SecondResizeCell.m */,
188 | );
189 | name = views;
190 | sourceTree = "";
191 | };
192 | E1B31A5E1A2F481A009E22F5 /* vendor */ = {
193 | isa = PBXGroup;
194 | children = (
195 | E1B606581A3970D00070859F /* SVProgressHUD */,
196 | E1B31A5F1A2F481A009E22F5 /* Masonry */,
197 | );
198 | path = vendor;
199 | sourceTree = "";
200 | };
201 | E1B31A5F1A2F481A009E22F5 /* Masonry */ = {
202 | isa = PBXGroup;
203 | children = (
204 | E1B31A601A2F481A009E22F5 /* category */,
205 | E1B31A631A2F481A009E22F5 /* MASCompositeConstraint.h */,
206 | E1B31A641A2F481A009E22F5 /* MASCompositeConstraint.m */,
207 | E1B31A651A2F481A009E22F5 /* MASConstraint+Private.h */,
208 | E1B31A661A2F481A009E22F5 /* MASConstraint.h */,
209 | E1B31A671A2F481A009E22F5 /* MASConstraint.m */,
210 | E1B31A681A2F481A009E22F5 /* MASConstraintMaker.h */,
211 | E1B31A691A2F481A009E22F5 /* MASConstraintMaker.m */,
212 | E1B31A6A1A2F481A009E22F5 /* MASLayoutConstraint.h */,
213 | E1B31A6B1A2F481A009E22F5 /* MASLayoutConstraint.m */,
214 | E1B31A6C1A2F481A009E22F5 /* Masonry.h */,
215 | E1B31A6D1A2F481A009E22F5 /* MASUtilities.h */,
216 | E1B31A6E1A2F481A009E22F5 /* MASViewAttribute.h */,
217 | E1B31A6F1A2F481A009E22F5 /* MASViewAttribute.m */,
218 | E1B31A701A2F481A009E22F5 /* MASViewConstraint.h */,
219 | E1B31A711A2F481A009E22F5 /* MASViewConstraint.m */,
220 | E1B31A721A2F481A009E22F5 /* NSArray+MASAdditions.h */,
221 | E1B31A731A2F481A009E22F5 /* NSArray+MASAdditions.m */,
222 | E1B31A741A2F481A009E22F5 /* NSArray+MASShorthandAdditions.h */,
223 | E1B31A751A2F481A009E22F5 /* NSLayoutConstraint+MASDebugAdditions.h */,
224 | E1B31A761A2F481A009E22F5 /* NSLayoutConstraint+MASDebugAdditions.m */,
225 | E1B31A771A2F481A009E22F5 /* View+MASAdditions.h */,
226 | E1B31A781A2F481A009E22F5 /* View+MASAdditions.m */,
227 | E1B31A791A2F481A009E22F5 /* View+MASShorthandAdditions.h */,
228 | );
229 | path = Masonry;
230 | sourceTree = "";
231 | };
232 | E1B31A601A2F481A009E22F5 /* category */ = {
233 | isa = PBXGroup;
234 | children = (
235 | E1B31A611A2F481A009E22F5 /* UIView+AverageRange.h */,
236 | E1B31A621A2F481A009E22F5 /* UIView+AverageRange.m */,
237 | );
238 | path = category;
239 | sourceTree = "";
240 | };
241 | E1B31A841A2F4E48009E22F5 /* controllers */ = {
242 | isa = PBXGroup;
243 | children = (
244 | E1B31A851A2F4E74009E22F5 /* AutoResizeCellController.h */,
245 | E1B31A861A2F4E74009E22F5 /* AutoResizeCellController.m */,
246 | );
247 | name = controllers;
248 | sourceTree = "";
249 | };
250 | E1B606511A396B220070859F /* images */ = {
251 | isa = PBXGroup;
252 | children = (
253 | E1B606521A396B220070859F /* avatar.jpeg */,
254 | E1B606531A396B220070859F /* avatar@2x.jpeg */,
255 | E1B606541A396B220070859F /* avatar@3x.jpeg */,
256 | );
257 | path = images;
258 | sourceTree = "";
259 | };
260 | E1B606581A3970D00070859F /* SVProgressHUD */ = {
261 | isa = PBXGroup;
262 | children = (
263 | E1B606591A3970D00070859F /* SVProgressHUD.bundle */,
264 | E1B6065A1A3970D10070859F /* SVProgressHUD.h */,
265 | E1B6065B1A3970D10070859F /* SVProgressHUD.m */,
266 | );
267 | path = SVProgressHUD;
268 | sourceTree = "";
269 | };
270 | /* End PBXGroup section */
271 |
272 | /* Begin PBXNativeTarget section */
273 | E1B31A301A2F43B5009E22F5 /* AutoResizeCellDemo */ = {
274 | isa = PBXNativeTarget;
275 | buildConfigurationList = E1B31A541A2F43B5009E22F5 /* Build configuration list for PBXNativeTarget "AutoResizeCellDemo" */;
276 | buildPhases = (
277 | E1B31A2D1A2F43B5009E22F5 /* Sources */,
278 | E1B31A2E1A2F43B5009E22F5 /* Frameworks */,
279 | E1B31A2F1A2F43B5009E22F5 /* Resources */,
280 | );
281 | buildRules = (
282 | );
283 | dependencies = (
284 | );
285 | name = AutoResizeCellDemo;
286 | productName = AutoResizeCellDemo;
287 | productReference = E1B31A311A2F43B5009E22F5 /* AutoResizeCellDemo.app */;
288 | productType = "com.apple.product-type.application";
289 | };
290 | E1B31A491A2F43B5009E22F5 /* AutoResizeCellDemoTests */ = {
291 | isa = PBXNativeTarget;
292 | buildConfigurationList = E1B31A571A2F43B5009E22F5 /* Build configuration list for PBXNativeTarget "AutoResizeCellDemoTests" */;
293 | buildPhases = (
294 | E1B31A461A2F43B5009E22F5 /* Sources */,
295 | E1B31A471A2F43B5009E22F5 /* Frameworks */,
296 | E1B31A481A2F43B5009E22F5 /* Resources */,
297 | );
298 | buildRules = (
299 | );
300 | dependencies = (
301 | E1B31A4C1A2F43B5009E22F5 /* PBXTargetDependency */,
302 | );
303 | name = AutoResizeCellDemoTests;
304 | productName = AutoResizeCellDemoTests;
305 | productReference = E1B31A4A1A2F43B5009E22F5 /* AutoResizeCellDemoTests.xctest */;
306 | productType = "com.apple.product-type.bundle.unit-test";
307 | };
308 | /* End PBXNativeTarget section */
309 |
310 | /* Begin PBXProject section */
311 | E1B31A291A2F43B5009E22F5 /* Project object */ = {
312 | isa = PBXProject;
313 | attributes = {
314 | LastUpgradeCheck = 0610;
315 | ORGANIZATIONNAME = Aevit;
316 | TargetAttributes = {
317 | E1B31A301A2F43B5009E22F5 = {
318 | CreatedOnToolsVersion = 6.1;
319 | };
320 | E1B31A491A2F43B5009E22F5 = {
321 | CreatedOnToolsVersion = 6.1;
322 | TestTargetID = E1B31A301A2F43B5009E22F5;
323 | };
324 | };
325 | };
326 | buildConfigurationList = E1B31A2C1A2F43B5009E22F5 /* Build configuration list for PBXProject "AutoResizeCellDemo" */;
327 | compatibilityVersion = "Xcode 3.2";
328 | developmentRegion = English;
329 | hasScannedForEncodings = 0;
330 | knownRegions = (
331 | en,
332 | Base,
333 | );
334 | mainGroup = E1B31A281A2F43B5009E22F5;
335 | productRefGroup = E1B31A321A2F43B5009E22F5 /* Products */;
336 | projectDirPath = "";
337 | projectRoot = "";
338 | targets = (
339 | E1B31A301A2F43B5009E22F5 /* AutoResizeCellDemo */,
340 | E1B31A491A2F43B5009E22F5 /* AutoResizeCellDemoTests */,
341 | );
342 | };
343 | /* End PBXProject section */
344 |
345 | /* Begin PBXResourcesBuildPhase section */
346 | E1B31A2F1A2F43B5009E22F5 /* Resources */ = {
347 | isa = PBXResourcesBuildPhase;
348 | buildActionMask = 2147483647;
349 | files = (
350 | E1B6065C1A3970D10070859F /* SVProgressHUD.bundle in Resources */,
351 | E1B606561A396B220070859F /* avatar@2x.jpeg in Resources */,
352 | E1B31A401A2F43B5009E22F5 /* Main.storyboard in Resources */,
353 | E1B31A451A2F43B5009E22F5 /* LaunchScreen.xib in Resources */,
354 | E1B606551A396B220070859F /* avatar.jpeg in Resources */,
355 | E1B606571A396B220070859F /* avatar@3x.jpeg in Resources */,
356 | E1B31A421A2F43B5009E22F5 /* Images.xcassets in Resources */,
357 | );
358 | runOnlyForDeploymentPostprocessing = 0;
359 | };
360 | E1B31A481A2F43B5009E22F5 /* Resources */ = {
361 | isa = PBXResourcesBuildPhase;
362 | buildActionMask = 2147483647;
363 | files = (
364 | );
365 | runOnlyForDeploymentPostprocessing = 0;
366 | };
367 | /* End PBXResourcesBuildPhase section */
368 |
369 | /* Begin PBXSourcesBuildPhase section */
370 | E1B31A2D1A2F43B5009E22F5 /* Sources */ = {
371 | isa = PBXSourcesBuildPhase;
372 | buildActionMask = 2147483647;
373 | files = (
374 | E1B31A821A2F481A009E22F5 /* NSLayoutConstraint+MASDebugAdditions.m in Sources */,
375 | E1B31A3D1A2F43B5009E22F5 /* ViewController.m in Sources */,
376 | E1B31A801A2F481A009E22F5 /* MASViewConstraint.m in Sources */,
377 | E1B31A7A1A2F481A009E22F5 /* UIView+AverageRange.m in Sources */,
378 | E1B31A3A1A2F43B5009E22F5 /* AppDelegate.m in Sources */,
379 | E1B6065D1A3970D10070859F /* SVProgressHUD.m in Sources */,
380 | E1B31A871A2F4E74009E22F5 /* AutoResizeCellController.m in Sources */,
381 | E1B31A5C1A2F46BB009E22F5 /* AutoResizeCell.m in Sources */,
382 | E1B31A831A2F481A009E22F5 /* View+MASAdditions.m in Sources */,
383 | E1B31A7B1A2F481A009E22F5 /* MASCompositeConstraint.m in Sources */,
384 | E1B31A7F1A2F481A009E22F5 /* MASViewAttribute.m in Sources */,
385 | E1B31A7D1A2F481A009E22F5 /* MASConstraintMaker.m in Sources */,
386 | E1B606501A3967190070859F /* SecondResizeCell.m in Sources */,
387 | E1B31A811A2F481A009E22F5 /* NSArray+MASAdditions.m in Sources */,
388 | E1B31A7C1A2F481A009E22F5 /* MASConstraint.m in Sources */,
389 | E1B31A7E1A2F481A009E22F5 /* MASLayoutConstraint.m in Sources */,
390 | E1B31A371A2F43B5009E22F5 /* main.m in Sources */,
391 | );
392 | runOnlyForDeploymentPostprocessing = 0;
393 | };
394 | E1B31A461A2F43B5009E22F5 /* Sources */ = {
395 | isa = PBXSourcesBuildPhase;
396 | buildActionMask = 2147483647;
397 | files = (
398 | E1B31A511A2F43B5009E22F5 /* AutoResizeCellDemoTests.m in Sources */,
399 | );
400 | runOnlyForDeploymentPostprocessing = 0;
401 | };
402 | /* End PBXSourcesBuildPhase section */
403 |
404 | /* Begin PBXTargetDependency section */
405 | E1B31A4C1A2F43B5009E22F5 /* PBXTargetDependency */ = {
406 | isa = PBXTargetDependency;
407 | target = E1B31A301A2F43B5009E22F5 /* AutoResizeCellDemo */;
408 | targetProxy = E1B31A4B1A2F43B5009E22F5 /* PBXContainerItemProxy */;
409 | };
410 | /* End PBXTargetDependency section */
411 |
412 | /* Begin PBXVariantGroup section */
413 | E1B31A3E1A2F43B5009E22F5 /* Main.storyboard */ = {
414 | isa = PBXVariantGroup;
415 | children = (
416 | E1B31A3F1A2F43B5009E22F5 /* Base */,
417 | );
418 | name = Main.storyboard;
419 | sourceTree = "";
420 | };
421 | E1B31A431A2F43B5009E22F5 /* LaunchScreen.xib */ = {
422 | isa = PBXVariantGroup;
423 | children = (
424 | E1B31A441A2F43B5009E22F5 /* Base */,
425 | );
426 | name = LaunchScreen.xib;
427 | sourceTree = "";
428 | };
429 | /* End PBXVariantGroup section */
430 |
431 | /* Begin XCBuildConfiguration section */
432 | E1B31A521A2F43B5009E22F5 /* Debug */ = {
433 | isa = XCBuildConfiguration;
434 | buildSettings = {
435 | ALWAYS_SEARCH_USER_PATHS = NO;
436 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
437 | CLANG_CXX_LIBRARY = "libc++";
438 | CLANG_ENABLE_MODULES = YES;
439 | CLANG_ENABLE_OBJC_ARC = YES;
440 | CLANG_WARN_BOOL_CONVERSION = YES;
441 | CLANG_WARN_CONSTANT_CONVERSION = YES;
442 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
443 | CLANG_WARN_EMPTY_BODY = YES;
444 | CLANG_WARN_ENUM_CONVERSION = YES;
445 | CLANG_WARN_INT_CONVERSION = YES;
446 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
447 | CLANG_WARN_UNREACHABLE_CODE = YES;
448 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
449 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
450 | COPY_PHASE_STRIP = NO;
451 | ENABLE_STRICT_OBJC_MSGSEND = YES;
452 | GCC_C_LANGUAGE_STANDARD = gnu99;
453 | GCC_DYNAMIC_NO_PIC = NO;
454 | GCC_OPTIMIZATION_LEVEL = 0;
455 | GCC_PREPROCESSOR_DEFINITIONS = (
456 | "DEBUG=1",
457 | "$(inherited)",
458 | );
459 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
460 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
461 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
462 | GCC_WARN_UNDECLARED_SELECTOR = YES;
463 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
464 | GCC_WARN_UNUSED_FUNCTION = YES;
465 | GCC_WARN_UNUSED_VARIABLE = YES;
466 | IPHONEOS_DEPLOYMENT_TARGET = 8.1;
467 | MTL_ENABLE_DEBUG_INFO = YES;
468 | ONLY_ACTIVE_ARCH = YES;
469 | SDKROOT = iphoneos;
470 | };
471 | name = Debug;
472 | };
473 | E1B31A531A2F43B5009E22F5 /* Release */ = {
474 | isa = XCBuildConfiguration;
475 | buildSettings = {
476 | ALWAYS_SEARCH_USER_PATHS = NO;
477 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
478 | CLANG_CXX_LIBRARY = "libc++";
479 | CLANG_ENABLE_MODULES = YES;
480 | CLANG_ENABLE_OBJC_ARC = YES;
481 | CLANG_WARN_BOOL_CONVERSION = YES;
482 | CLANG_WARN_CONSTANT_CONVERSION = YES;
483 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
484 | CLANG_WARN_EMPTY_BODY = YES;
485 | CLANG_WARN_ENUM_CONVERSION = YES;
486 | CLANG_WARN_INT_CONVERSION = YES;
487 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
488 | CLANG_WARN_UNREACHABLE_CODE = YES;
489 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
490 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
491 | COPY_PHASE_STRIP = YES;
492 | ENABLE_NS_ASSERTIONS = NO;
493 | ENABLE_STRICT_OBJC_MSGSEND = YES;
494 | GCC_C_LANGUAGE_STANDARD = gnu99;
495 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
496 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
497 | GCC_WARN_UNDECLARED_SELECTOR = YES;
498 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
499 | GCC_WARN_UNUSED_FUNCTION = YES;
500 | GCC_WARN_UNUSED_VARIABLE = YES;
501 | IPHONEOS_DEPLOYMENT_TARGET = 8.1;
502 | MTL_ENABLE_DEBUG_INFO = NO;
503 | SDKROOT = iphoneos;
504 | VALIDATE_PRODUCT = YES;
505 | };
506 | name = Release;
507 | };
508 | E1B31A551A2F43B5009E22F5 /* Debug */ = {
509 | isa = XCBuildConfiguration;
510 | buildSettings = {
511 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
512 | INFOPLIST_FILE = AutoResizeCellDemo/Info.plist;
513 | IPHONEOS_DEPLOYMENT_TARGET = 7.0;
514 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
515 | OTHER_LDFLAGS = "-ObjC";
516 | PRODUCT_NAME = "$(TARGET_NAME)";
517 | };
518 | name = Debug;
519 | };
520 | E1B31A561A2F43B5009E22F5 /* Release */ = {
521 | isa = XCBuildConfiguration;
522 | buildSettings = {
523 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
524 | INFOPLIST_FILE = AutoResizeCellDemo/Info.plist;
525 | IPHONEOS_DEPLOYMENT_TARGET = 7.0;
526 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
527 | OTHER_LDFLAGS = "-ObjC";
528 | PRODUCT_NAME = "$(TARGET_NAME)";
529 | };
530 | name = Release;
531 | };
532 | E1B31A581A2F43B5009E22F5 /* Debug */ = {
533 | isa = XCBuildConfiguration;
534 | buildSettings = {
535 | BUNDLE_LOADER = "$(TEST_HOST)";
536 | FRAMEWORK_SEARCH_PATHS = (
537 | "$(SDKROOT)/Developer/Library/Frameworks",
538 | "$(inherited)",
539 | );
540 | GCC_PREPROCESSOR_DEFINITIONS = (
541 | "DEBUG=1",
542 | "$(inherited)",
543 | );
544 | INFOPLIST_FILE = AutoResizeCellDemoTests/Info.plist;
545 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
546 | PRODUCT_NAME = "$(TARGET_NAME)";
547 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AutoResizeCellDemo.app/AutoResizeCellDemo";
548 | };
549 | name = Debug;
550 | };
551 | E1B31A591A2F43B5009E22F5 /* Release */ = {
552 | isa = XCBuildConfiguration;
553 | buildSettings = {
554 | BUNDLE_LOADER = "$(TEST_HOST)";
555 | FRAMEWORK_SEARCH_PATHS = (
556 | "$(SDKROOT)/Developer/Library/Frameworks",
557 | "$(inherited)",
558 | );
559 | INFOPLIST_FILE = AutoResizeCellDemoTests/Info.plist;
560 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
561 | PRODUCT_NAME = "$(TARGET_NAME)";
562 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AutoResizeCellDemo.app/AutoResizeCellDemo";
563 | };
564 | name = Release;
565 | };
566 | /* End XCBuildConfiguration section */
567 |
568 | /* Begin XCConfigurationList section */
569 | E1B31A2C1A2F43B5009E22F5 /* Build configuration list for PBXProject "AutoResizeCellDemo" */ = {
570 | isa = XCConfigurationList;
571 | buildConfigurations = (
572 | E1B31A521A2F43B5009E22F5 /* Debug */,
573 | E1B31A531A2F43B5009E22F5 /* Release */,
574 | );
575 | defaultConfigurationIsVisible = 0;
576 | defaultConfigurationName = Release;
577 | };
578 | E1B31A541A2F43B5009E22F5 /* Build configuration list for PBXNativeTarget "AutoResizeCellDemo" */ = {
579 | isa = XCConfigurationList;
580 | buildConfigurations = (
581 | E1B31A551A2F43B5009E22F5 /* Debug */,
582 | E1B31A561A2F43B5009E22F5 /* Release */,
583 | );
584 | defaultConfigurationIsVisible = 0;
585 | defaultConfigurationName = Release;
586 | };
587 | E1B31A571A2F43B5009E22F5 /* Build configuration list for PBXNativeTarget "AutoResizeCellDemoTests" */ = {
588 | isa = XCConfigurationList;
589 | buildConfigurations = (
590 | E1B31A581A2F43B5009E22F5 /* Debug */,
591 | E1B31A591A2F43B5009E22F5 /* Release */,
592 | );
593 | defaultConfigurationIsVisible = 0;
594 | defaultConfigurationName = Release;
595 | };
596 | /* End XCConfigurationList section */
597 | };
598 | rootObject = E1B31A291A2F43B5009E22F5 /* Project object */;
599 | }
600 |
--------------------------------------------------------------------------------
/AutoResizeCellDemo/AutoResizeCellDemo/vendor/SVProgressHUD/SVProgressHUD.m:
--------------------------------------------------------------------------------
1 | //
2 | // SVProgressHUD.m
3 | //
4 | // Created by Sam Vermette on 27.03.11.
5 | // Copyright 2011 Sam Vermette. All rights reserved.
6 | //
7 | // https://github.com/samvermette/SVProgressHUD
8 | //
9 |
10 | #if !__has_feature(objc_arc)
11 | #error SVProgressHUD is ARC only. Either turn on ARC for the project or use -fobjc-arc flag
12 | #endif
13 |
14 | #import "SVProgressHUD.h"
15 | #import
16 |
17 | NSString * const SVProgressHUDDidReceiveTouchEventNotification = @"SVProgressHUDDidReceiveTouchEventNotification";
18 | NSString * const SVProgressHUDWillDisappearNotification = @"SVProgressHUDWillDisappearNotification";
19 | NSString * const SVProgressHUDDidDisappearNotification = @"SVProgressHUDDidDisappearNotification";
20 | NSString * const SVProgressHUDWillAppearNotification = @"SVProgressHUDWillAppearNotification";
21 | NSString * const SVProgressHUDDidAppearNotification = @"SVProgressHUDDidAppearNotification";
22 |
23 | NSString * const SVProgressHUDStatusUserInfoKey = @"SVProgressHUDStatusUserInfoKey";
24 |
25 | static UIColor *SVProgressHUDBackgroundColor;
26 | static UIColor *SVProgressHUDForegroundColor;
27 | static CGFloat SVProgressHUDRingThickness;
28 | static UIFont *SVProgressHUDFont;
29 | static UIImage *SVProgressHUDSuccessImage;
30 | static UIImage *SVProgressHUDErrorImage;
31 |
32 | static const CGFloat SVProgressHUDRingRadius = 18;
33 | static const CGFloat SVProgressHUDRingNoTextRadius = 24;
34 | static const CGFloat SVProgressHUDParallaxDepthPoints = 10;
35 |
36 | @interface SVProgressHUD ()
37 |
38 | @property (nonatomic, readwrite) SVProgressHUDMaskType maskType;
39 | @property (nonatomic, strong, readonly) NSTimer *fadeOutTimer;
40 | @property (nonatomic, readonly, getter = isClear) BOOL clear;
41 |
42 | @property (nonatomic, strong) UIControl *overlayView;
43 | @property (nonatomic, strong) UIView *hudView;
44 | @property (nonatomic, strong) UILabel *stringLabel;
45 | @property (nonatomic, strong) UIImageView *imageView;
46 | @property (nonatomic, strong) SVIndefiniteAnimatedView *indefiniteAnimatedView;
47 |
48 | @property (nonatomic, readwrite) CGFloat progress;
49 | @property (nonatomic, readwrite) NSUInteger activityCount;
50 | @property (nonatomic, strong) CAShapeLayer *backgroundRingLayer;
51 | @property (nonatomic, strong) CAShapeLayer *ringLayer;
52 |
53 | @property (nonatomic, readonly) CGFloat visibleKeyboardHeight;
54 | @property (nonatomic, assign) UIOffset offsetFromCenter;
55 |
56 |
57 | - (void)showProgress:(float)progress
58 | status:(NSString*)string
59 | maskType:(SVProgressHUDMaskType)hudMaskType;
60 |
61 | - (void)showImage:(UIImage*)image
62 | status:(NSString*)status
63 | duration:(NSTimeInterval)duration;
64 |
65 | - (void)dismiss;
66 |
67 | - (void)setStatus:(NSString*)string;
68 | - (void)registerNotifications;
69 | - (NSDictionary *)notificationUserInfo;
70 | - (void)moveToPoint:(CGPoint)newCenter rotateAngle:(CGFloat)angle;
71 | - (void)positionHUD:(NSNotification*)notification;
72 | - (NSTimeInterval)displayDurationForString:(NSString*)string;
73 |
74 | @end
75 |
76 |
77 | @implementation SVProgressHUD
78 |
79 | + (SVProgressHUD*)sharedView {
80 | static dispatch_once_t once;
81 | static SVProgressHUD *sharedView;
82 | dispatch_once(&once, ^ { sharedView = [[self alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; });
83 | return sharedView;
84 | }
85 |
86 | #pragma mark - Setters
87 |
88 | + (void)setStatus:(NSString *)string {
89 | [[self sharedView] setStatus:string];
90 | }
91 |
92 | + (void)setBackgroundColor:(UIColor *)color {
93 | [self sharedView].hudView.backgroundColor = color;
94 | SVProgressHUDBackgroundColor = color;
95 | }
96 |
97 | + (void)setForegroundColor:(UIColor *)color {
98 | [self sharedView];
99 | SVProgressHUDForegroundColor = color;
100 | }
101 |
102 | + (void)setFont:(UIFont *)font {
103 | [self sharedView];
104 | SVProgressHUDFont = font;
105 | }
106 |
107 | + (void)setRingThickness:(CGFloat)width {
108 | [self sharedView];
109 | SVProgressHUDRingThickness = width;
110 | }
111 |
112 | + (void)setSuccessImage:(UIImage *)image {
113 | [self sharedView];
114 | SVProgressHUDSuccessImage = image;
115 | }
116 |
117 | + (void)setErrorImage:(UIImage *)image {
118 | [self sharedView];
119 | SVProgressHUDErrorImage = image;
120 | }
121 |
122 | #pragma mark - Show Methods
123 |
124 | + (void)show {
125 | [[self sharedView] showProgress:-1 status:nil maskType:SVProgressHUDMaskTypeNone];
126 | }
127 |
128 | + (void)showWithStatus:(NSString *)status {
129 | [[self sharedView] showProgress:-1 status:status maskType:SVProgressHUDMaskTypeNone];
130 | }
131 |
132 | + (void)showWithMaskType:(SVProgressHUDMaskType)maskType {
133 | [[self sharedView] showProgress:-1 status:nil maskType:maskType];
134 | }
135 |
136 | + (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType {
137 | [[self sharedView] showProgress:-1 status:status maskType:maskType];
138 | }
139 |
140 | + (void)showProgress:(float)progress {
141 | [[self sharedView] showProgress:progress status:nil maskType:SVProgressHUDMaskTypeNone];
142 | }
143 |
144 | + (void)showProgress:(float)progress status:(NSString *)status {
145 | [[self sharedView] showProgress:progress status:status maskType:SVProgressHUDMaskTypeNone];
146 | }
147 |
148 | + (void)showProgress:(float)progress status:(NSString *)status maskType:(SVProgressHUDMaskType)maskType {
149 | [[self sharedView] showProgress:progress status:status maskType:maskType];
150 | }
151 |
152 | #pragma mark - Show then dismiss methods
153 |
154 | + (void)showSuccessWithStatus:(NSString *)string {
155 | [self sharedView];
156 | [self showImage:SVProgressHUDSuccessImage status:string];
157 | }
158 |
159 | + (void)showErrorWithStatus:(NSString *)string {
160 | [self sharedView];
161 | [self showImage:SVProgressHUDErrorImage status:string];
162 | }
163 |
164 | + (void)showImage:(UIImage *)image status:(NSString *)string {
165 | NSTimeInterval displayInterval = [[SVProgressHUD sharedView] displayDurationForString:string];
166 | [[self sharedView] showImage:image status:string duration:displayInterval];
167 | }
168 |
169 |
170 | #pragma mark - Dismiss Methods
171 |
172 | + (void)popActivity {
173 | [self sharedView].activityCount--;
174 | if([self sharedView].activityCount == 0)
175 | [[self sharedView] dismiss];
176 | }
177 |
178 | + (void)dismiss {
179 | if ([self isVisible]) {
180 | [[self sharedView] dismiss];
181 | }
182 | }
183 |
184 |
185 | #pragma mark - Offset
186 |
187 | + (void)setOffsetFromCenter:(UIOffset)offset {
188 | [self sharedView].offsetFromCenter = offset;
189 | }
190 |
191 | + (void)resetOffsetFromCenter {
192 | [self setOffsetFromCenter:UIOffsetZero];
193 | }
194 |
195 | #pragma mark - Instance Methods
196 |
197 | - (id)initWithFrame:(CGRect)frame {
198 |
199 | if ((self = [super initWithFrame:frame])) {
200 | self.userInteractionEnabled = NO;
201 | self.backgroundColor = [UIColor clearColor];
202 | self.alpha = 0;
203 | self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
204 | self.activityCount = 0;
205 |
206 | SVProgressHUDBackgroundColor = [UIColor whiteColor];
207 | SVProgressHUDForegroundColor = [UIColor blackColor];
208 | if ([UIFont respondsToSelector:@selector(preferredFontForTextStyle:)]) {
209 | SVProgressHUDFont = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
210 | } else {
211 | SVProgressHUDFont = [UIFont systemFontOfSize:14.0];
212 | SVProgressHUDBackgroundColor = [UIColor colorWithWhite:0 alpha:0.8];
213 | SVProgressHUDForegroundColor = [UIColor whiteColor];
214 | }
215 | if ([[UIImage class] instancesRespondToSelector:@selector(imageWithRenderingMode:)]) {
216 | SVProgressHUDSuccessImage = [[UIImage imageNamed:@"SVProgressHUD.bundle/success"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
217 | SVProgressHUDErrorImage = [[UIImage imageNamed:@"SVProgressHUD.bundle/error"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
218 | } else {
219 | SVProgressHUDSuccessImage = [UIImage imageNamed:@"SVProgressHUD.bundle/success"];
220 | SVProgressHUDErrorImage = [UIImage imageNamed:@"SVProgressHUD.bundle/error"];
221 | }
222 | SVProgressHUDRingThickness = 4;
223 | }
224 |
225 | return self;
226 | }
227 |
228 | - (void)drawRect:(CGRect)rect {
229 |
230 | CGContextRef context = UIGraphicsGetCurrentContext();
231 |
232 | switch (self.maskType) {
233 |
234 | case SVProgressHUDMaskTypeBlack: {
235 | [[UIColor colorWithWhite:0 alpha:0.5] set];
236 | CGContextFillRect(context, self.bounds);
237 | break;
238 | }
239 |
240 | case SVProgressHUDMaskTypeGradient: {
241 |
242 | size_t locationsCount = 2;
243 | CGFloat locations[2] = {0.0f, 1.0f};
244 | CGFloat colors[8] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.75f};
245 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
246 | CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount);
247 | CGColorSpaceRelease(colorSpace);
248 |
249 | CGFloat freeHeight = self.bounds.size.height - self.visibleKeyboardHeight;
250 |
251 | CGPoint center = CGPointMake(self.bounds.size.width/2, freeHeight/2);
252 | float radius = MIN(self.bounds.size.width , self.bounds.size.height) ;
253 | CGContextDrawRadialGradient (context, gradient, center, 0, center, radius, kCGGradientDrawsAfterEndLocation);
254 | CGGradientRelease(gradient);
255 |
256 | break;
257 | }
258 | }
259 | }
260 |
261 | - (void)updatePosition {
262 |
263 | CGFloat hudWidth = 100;
264 | CGFloat hudHeight = 100;
265 | CGFloat stringHeightBuffer = 20;
266 | CGFloat stringAndImageHeightBuffer = 80;
267 |
268 | CGFloat stringWidth = 0;
269 | CGFloat stringHeight = 0;
270 | CGRect labelRect = CGRectZero;
271 |
272 | NSString *string = self.stringLabel.text;
273 | // False if it's text-only
274 | BOOL imageUsed = (self.imageView.image) || (self.imageView.hidden);
275 |
276 | if(string) {
277 | CGSize constraintSize = CGSizeMake(200, 300);
278 | CGRect stringRect;
279 | if ([string respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) {
280 | stringRect = [string boundingRectWithSize:constraintSize
281 | options:(NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin)
282 | attributes:@{NSFontAttributeName: self.stringLabel.font}
283 | context:NULL];
284 | } else {
285 | CGSize stringSize;
286 | #ifdef __IPHONE_8_0
287 | stringSize = [string sizeWithAttributes:@{NSFontAttributeName:[UIFont fontWithName:self.stringLabel.font.fontName size:self.stringLabel.font.pointSize]}];
288 | #else
289 | stringSize = [string sizeWithFont:self.stringLabel.font constrainedToSize:CGSizeMake(200, 300)];
290 | #endif
291 | stringRect = CGRectMake(0.0f, 0.0f, stringSize.width, stringSize.height);
292 | }
293 | stringWidth = stringRect.size.width;
294 | stringHeight = ceil(stringRect.size.height);
295 |
296 | if (imageUsed)
297 | hudHeight = stringAndImageHeightBuffer + stringHeight;
298 | else
299 | hudHeight = stringHeightBuffer + stringHeight;
300 |
301 | if(stringWidth > hudWidth)
302 | hudWidth = ceil(stringWidth/2)*2;
303 |
304 | CGFloat labelRectY = imageUsed ? 68 : 9;
305 |
306 | if(hudHeight > 100) {
307 | labelRect = CGRectMake(12, labelRectY, hudWidth, stringHeight);
308 | hudWidth+=24;
309 | } else {
310 | hudWidth+=24;
311 | labelRect = CGRectMake(0, labelRectY, hudWidth, stringHeight);
312 | }
313 | }
314 |
315 | self.hudView.bounds = CGRectMake(0, 0, hudWidth, hudHeight);
316 |
317 | if(string)
318 | self.imageView.center = CGPointMake(CGRectGetWidth(self.hudView.bounds)/2, 36);
319 | else
320 | self.imageView.center = CGPointMake(CGRectGetWidth(self.hudView.bounds)/2, CGRectGetHeight(self.hudView.bounds)/2);
321 |
322 | self.stringLabel.hidden = NO;
323 | self.stringLabel.frame = labelRect;
324 |
325 | [CATransaction begin];
326 | [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
327 |
328 | if(string) {
329 | self.indefiniteAnimatedView.radius = SVProgressHUDRingRadius;
330 | [self.indefiniteAnimatedView sizeToFit];
331 |
332 | CGPoint center = CGPointMake((CGRectGetWidth(self.hudView.bounds)/2), 36);
333 | self.indefiniteAnimatedView.center = center;
334 |
335 | if(self.progress != -1)
336 | self.backgroundRingLayer.position = self.ringLayer.position = CGPointMake((CGRectGetWidth(self.hudView.bounds)/2), 36);
337 | }
338 | else {
339 | self.indefiniteAnimatedView.radius = SVProgressHUDRingNoTextRadius;
340 | [self.indefiniteAnimatedView sizeToFit];
341 |
342 | CGPoint center = CGPointMake((CGRectGetWidth(self.hudView.bounds)/2), CGRectGetHeight(self.hudView.bounds)/2);
343 | self.indefiniteAnimatedView.center = center;
344 |
345 | if(self.progress != -1)
346 | self.backgroundRingLayer.position = self.ringLayer.position = CGPointMake((CGRectGetWidth(self.hudView.bounds)/2), CGRectGetHeight(self.hudView.bounds)/2);
347 | }
348 |
349 | [CATransaction commit];
350 | }
351 |
352 | - (void)setStatus:(NSString *)string {
353 |
354 | self.stringLabel.text = string;
355 | [self updatePosition];
356 |
357 | }
358 |
359 | - (void)setFadeOutTimer:(NSTimer *)newTimer {
360 |
361 | if(_fadeOutTimer)
362 | [_fadeOutTimer invalidate], _fadeOutTimer = nil;
363 |
364 | if(newTimer)
365 | _fadeOutTimer = newTimer;
366 | }
367 |
368 |
369 | - (void)registerNotifications {
370 | [[NSNotificationCenter defaultCenter] addObserver:self
371 | selector:@selector(positionHUD:)
372 | name:UIApplicationDidChangeStatusBarOrientationNotification
373 | object:nil];
374 |
375 | [[NSNotificationCenter defaultCenter] addObserver:self
376 | selector:@selector(positionHUD:)
377 | name:UIKeyboardWillHideNotification
378 | object:nil];
379 |
380 | [[NSNotificationCenter defaultCenter] addObserver:self
381 | selector:@selector(positionHUD:)
382 | name:UIKeyboardDidHideNotification
383 | object:nil];
384 |
385 | [[NSNotificationCenter defaultCenter] addObserver:self
386 | selector:@selector(positionHUD:)
387 | name:UIKeyboardWillShowNotification
388 | object:nil];
389 |
390 | [[NSNotificationCenter defaultCenter] addObserver:self
391 | selector:@selector(positionHUD:)
392 | name:UIKeyboardDidShowNotification
393 | object:nil];
394 | }
395 |
396 |
397 | - (NSDictionary *)notificationUserInfo
398 | {
399 | return (self.stringLabel.text ? @{SVProgressHUDStatusUserInfoKey : self.stringLabel.text} : nil);
400 | }
401 |
402 |
403 | - (void)positionHUD:(NSNotification*)notification {
404 |
405 | CGFloat keyboardHeight;
406 | double animationDuration;
407 |
408 | UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
409 | // no transforms applied to window in iOS 8, but only if compiled with iOS 8 sdk as base sdk, otherwise system supports old rotation logic.
410 | BOOL ignoreOrientation = NO;
411 | #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
412 | if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
413 | ignoreOrientation = YES;
414 | }
415 | #endif
416 |
417 | if(notification) {
418 | NSDictionary* keyboardInfo = [notification userInfo];
419 | CGRect keyboardFrame = [[keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
420 | animationDuration = [[keyboardInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
421 |
422 | if(notification.name == UIKeyboardWillShowNotification || notification.name == UIKeyboardDidShowNotification) {
423 | if(ignoreOrientation || UIInterfaceOrientationIsPortrait(orientation))
424 | keyboardHeight = keyboardFrame.size.height;
425 | else
426 | keyboardHeight = keyboardFrame.size.width;
427 | } else
428 | keyboardHeight = 0;
429 | } else {
430 | keyboardHeight = self.visibleKeyboardHeight;
431 | }
432 |
433 | CGRect orientationFrame = self.window.bounds;
434 | CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
435 |
436 | if(!ignoreOrientation && UIInterfaceOrientationIsLandscape(orientation)) {
437 | float temp = orientationFrame.size.width;
438 | orientationFrame.size.width = orientationFrame.size.height;
439 | orientationFrame.size.height = temp;
440 |
441 | temp = statusBarFrame.size.width;
442 | statusBarFrame.size.width = statusBarFrame.size.height;
443 | statusBarFrame.size.height = temp;
444 | }
445 |
446 | CGFloat activeHeight = orientationFrame.size.height;
447 |
448 | if(keyboardHeight > 0)
449 | activeHeight += statusBarFrame.size.height*2;
450 |
451 | activeHeight -= keyboardHeight;
452 | CGFloat posY = floor(activeHeight*0.45);
453 | CGFloat posX = orientationFrame.size.width/2;
454 |
455 | CGPoint newCenter;
456 | CGFloat rotateAngle;
457 |
458 | if (ignoreOrientation) {
459 | rotateAngle = 0.0;
460 | newCenter = CGPointMake(posX, posY);
461 | } else {
462 | switch (orientation) {
463 | case UIInterfaceOrientationPortraitUpsideDown:
464 | rotateAngle = M_PI;
465 | newCenter = CGPointMake(posX, orientationFrame.size.height-posY);
466 | break;
467 | case UIInterfaceOrientationLandscapeLeft:
468 | rotateAngle = -M_PI/2.0f;
469 | newCenter = CGPointMake(posY, posX);
470 | break;
471 | case UIInterfaceOrientationLandscapeRight:
472 | rotateAngle = M_PI/2.0f;
473 | newCenter = CGPointMake(orientationFrame.size.height-posY, posX);
474 | break;
475 | default: // as UIInterfaceOrientationPortrait
476 | rotateAngle = 0.0;
477 | newCenter = CGPointMake(posX, posY);
478 | break;
479 | }
480 | }
481 |
482 | if(notification) {
483 | [UIView animateWithDuration:animationDuration
484 | delay:0
485 | options:UIViewAnimationOptionAllowUserInteraction
486 | animations:^{
487 | [self moveToPoint:newCenter rotateAngle:rotateAngle];
488 | } completion:NULL];
489 | }
490 |
491 | else {
492 | [self moveToPoint:newCenter rotateAngle:rotateAngle];
493 | }
494 |
495 | }
496 |
497 | - (void)moveToPoint:(CGPoint)newCenter rotateAngle:(CGFloat)angle {
498 | self.hudView.transform = CGAffineTransformMakeRotation(angle);
499 | self.hudView.center = CGPointMake(newCenter.x + self.offsetFromCenter.horizontal, newCenter.y + self.offsetFromCenter.vertical);
500 | }
501 |
502 | - (void)overlayViewDidReceiveTouchEvent:(id)sender forEvent:(UIEvent *)event {
503 | [[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDDidReceiveTouchEventNotification object:event];
504 | }
505 |
506 | #pragma mark - Master show/dismiss methods
507 |
508 | - (void)showProgress:(float)progress status:(NSString*)string maskType:(SVProgressHUDMaskType)hudMaskType {
509 |
510 | if(!self.overlayView.superview){
511 | NSEnumerator *frontToBackWindows = [[[UIApplication sharedApplication]windows]reverseObjectEnumerator];
512 |
513 | for (UIWindow *window in frontToBackWindows)
514 | if (window.windowLevel == UIWindowLevelNormal) {
515 | [window addSubview:self.overlayView];
516 | break;
517 | }
518 | }
519 |
520 | if(!self.superview)
521 | [self.overlayView addSubview:self];
522 |
523 | self.fadeOutTimer = nil;
524 | self.imageView.hidden = YES;
525 | self.maskType = hudMaskType;
526 | self.progress = progress;
527 |
528 | self.stringLabel.text = string;
529 | [self updatePosition];
530 |
531 | if(progress >= 0) {
532 | self.imageView.image = nil;
533 | self.imageView.hidden = NO;
534 | [self.indefiniteAnimatedView removeFromSuperview];
535 |
536 | self.ringLayer.strokeEnd = progress;
537 |
538 | if(progress == 0)
539 | self.activityCount++;
540 | }
541 | else {
542 | self.activityCount++;
543 | [self cancelRingLayerAnimation];
544 | [self.hudView addSubview:self.indefiniteAnimatedView];
545 | }
546 |
547 | if(self.maskType != SVProgressHUDMaskTypeNone) {
548 | self.overlayView.userInteractionEnabled = YES;
549 | self.accessibilityLabel = string;
550 | self.isAccessibilityElement = YES;
551 | }
552 | else {
553 | self.overlayView.userInteractionEnabled = NO;
554 | self.hudView.accessibilityLabel = string;
555 | self.hudView.isAccessibilityElement = YES;
556 | }
557 |
558 | [self.overlayView setHidden:NO];
559 | self.overlayView.backgroundColor = [UIColor clearColor];
560 | [self positionHUD:nil];
561 |
562 | if(self.alpha != 1) {
563 | NSDictionary *userInfo = [self notificationUserInfo];
564 | [[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDWillAppearNotification
565 | object:nil
566 | userInfo:userInfo];
567 |
568 | [self registerNotifications];
569 | self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 1.3, 1.3);
570 |
571 | if(self.isClear) {
572 | self.alpha = 1;
573 | self.hudView.alpha = 0;
574 | }
575 |
576 | [UIView animateWithDuration:0.15
577 | delay:0
578 | options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState
579 | animations:^{
580 | self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 1/1.3, 1/1.3);
581 |
582 | if(self.isClear) // handle iOS 7 UIToolbar not answer well to hierarchy opacity change
583 | self.hudView.alpha = 1;
584 | else
585 | self.alpha = 1;
586 | }
587 | completion:^(BOOL finished){
588 | [[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDDidAppearNotification
589 | object:nil
590 | userInfo:userInfo];
591 | UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);
592 | UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, string);
593 | }];
594 |
595 | [self setNeedsDisplay];
596 | }
597 | }
598 |
599 | - (UIImage *)image:(UIImage *)image withTintColor:(UIColor *)color
600 | {
601 | CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
602 | UIGraphicsBeginImageContextWithOptions(rect.size, NO, image.scale);
603 | CGContextRef c = UIGraphicsGetCurrentContext();
604 | [image drawInRect:rect];
605 | CGContextSetFillColorWithColor(c, [color CGColor]);
606 | CGContextSetBlendMode(c, kCGBlendModeSourceAtop);
607 | CGContextFillRect(c, rect);
608 | UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
609 | UIGraphicsEndImageContext();
610 | return tintedImage;
611 | }
612 |
613 | - (void)showImage:(UIImage *)image status:(NSString *)string duration:(NSTimeInterval)duration {
614 | self.progress = -1;
615 | [self cancelRingLayerAnimation];
616 |
617 | if(![self.class isVisible])
618 | [self.class show];
619 |
620 | if ([self.imageView respondsToSelector:@selector(setTintColor:)]) {
621 | self.imageView.tintColor = SVProgressHUDForegroundColor;
622 | } else {
623 | image = [self image:image withTintColor:SVProgressHUDForegroundColor];
624 | }
625 | self.imageView.image = image;
626 | self.imageView.hidden = NO;
627 |
628 | self.stringLabel.text = string;
629 | [self updatePosition];
630 | [self.indefiniteAnimatedView removeFromSuperview];
631 |
632 | if(self.maskType != SVProgressHUDMaskTypeNone) {
633 | self.accessibilityLabel = string;
634 | self.isAccessibilityElement = YES;
635 | } else {
636 | self.hudView.accessibilityLabel = string;
637 | self.hudView.isAccessibilityElement = YES;
638 | }
639 |
640 | UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);
641 | UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, string);
642 |
643 | self.fadeOutTimer = [NSTimer timerWithTimeInterval:duration target:self selector:@selector(dismiss) userInfo:nil repeats:NO];
644 | [[NSRunLoop mainRunLoop] addTimer:self.fadeOutTimer forMode:NSRunLoopCommonModes];
645 | }
646 |
647 | - (void)dismiss {
648 | NSDictionary *userInfo = [self notificationUserInfo];
649 | [[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDWillDisappearNotification
650 | object:nil
651 | userInfo:userInfo];
652 |
653 | self.activityCount = 0;
654 | [UIView animateWithDuration:0.15
655 | delay:0
656 | options:UIViewAnimationCurveEaseIn | UIViewAnimationOptionAllowUserInteraction
657 | animations:^{
658 | self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 0.8, 0.8);
659 | if(self.isClear) // handle iOS 7 UIToolbar not answer well to hierarchy opacity change
660 | self.hudView.alpha = 0;
661 | else
662 | self.alpha = 0;
663 | }
664 | completion:^(BOOL finished){
665 | if(self.alpha == 0 || self.hudView.alpha == 0) {
666 | self.alpha = 0;
667 | self.hudView.alpha = 0;
668 |
669 | [[NSNotificationCenter defaultCenter] removeObserver:self];
670 | [self cancelRingLayerAnimation];
671 | [_hudView removeFromSuperview];
672 | _hudView = nil;
673 |
674 | [_overlayView removeFromSuperview];
675 | _overlayView = nil;
676 |
677 | [_indefiniteAnimatedView removeFromSuperview];
678 | _indefiniteAnimatedView = nil;
679 |
680 | UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);
681 |
682 | [[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDDidDisappearNotification
683 | object:nil
684 | userInfo:userInfo];
685 |
686 | // Tell the rootViewController to update the StatusBar appearance
687 | UIViewController *rootController = [[UIApplication sharedApplication] keyWindow].rootViewController;
688 | if ([rootController respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
689 | [rootController setNeedsStatusBarAppearanceUpdate];
690 | }
691 | // uncomment to make sure UIWindow is gone from app.windows
692 | //NSLog(@"%@", [UIApplication sharedApplication].windows);
693 | //NSLog(@"keyWindow = %@", [UIApplication sharedApplication].keyWindow);
694 | }
695 | }];
696 | }
697 |
698 |
699 | #pragma mark - Ring progress animation
700 |
701 | - (SVIndefiniteAnimatedView *)indefiniteAnimatedView {
702 | if (_indefiniteAnimatedView == nil) {
703 | _indefiniteAnimatedView = [[SVIndefiniteAnimatedView alloc] initWithFrame:CGRectZero];
704 | _indefiniteAnimatedView.radius = self.stringLabel.text ? SVProgressHUDRingRadius : SVProgressHUDRingNoTextRadius;
705 | [_indefiniteAnimatedView sizeToFit];
706 | }
707 | return _indefiniteAnimatedView;
708 | }
709 |
710 | - (CAShapeLayer *)ringLayer {
711 | if(!_ringLayer) {
712 | CGPoint center = CGPointMake(CGRectGetWidth(_hudView.frame)/2, CGRectGetHeight(_hudView.frame)/2);
713 | _ringLayer = [self createRingLayerWithCenter:center
714 | radius:SVProgressHUDRingRadius
715 | lineWidth:SVProgressHUDRingThickness
716 | color:SVProgressHUDForegroundColor];
717 | [self.hudView.layer addSublayer:_ringLayer];
718 | }
719 | return _ringLayer;
720 | }
721 |
722 | - (CAShapeLayer *)backgroundRingLayer {
723 | if(!_backgroundRingLayer) {
724 | CGPoint center = CGPointMake(CGRectGetWidth(_hudView.frame)/2, CGRectGetHeight(_hudView.frame)/2);
725 | _backgroundRingLayer = [self createRingLayerWithCenter:center
726 | radius:SVProgressHUDRingRadius
727 | lineWidth:SVProgressHUDRingThickness
728 | color:[SVProgressHUDForegroundColor colorWithAlphaComponent:0.1]];
729 | _backgroundRingLayer.strokeEnd = 1;
730 | [self.hudView.layer addSublayer:_backgroundRingLayer];
731 | }
732 | return _backgroundRingLayer;
733 | }
734 |
735 | - (void)cancelRingLayerAnimation {
736 | [CATransaction begin];
737 | [CATransaction setDisableActions:YES];
738 | [_hudView.layer removeAllAnimations];
739 |
740 | _ringLayer.strokeEnd = 0.0f;
741 | if (_ringLayer.superlayer) {
742 | [_ringLayer removeFromSuperlayer];
743 | }
744 | _ringLayer = nil;
745 |
746 | if (_backgroundRingLayer.superlayer) {
747 | [_backgroundRingLayer removeFromSuperlayer];
748 | }
749 | _backgroundRingLayer = nil;
750 |
751 | [CATransaction commit];
752 | }
753 |
754 | - (CAShapeLayer *)createRingLayerWithCenter:(CGPoint)center radius:(CGFloat)radius lineWidth:(CGFloat)lineWidth color:(UIColor *)color {
755 |
756 | UIBezierPath* smoothedPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(radius, radius) radius:radius startAngle:-M_PI_2 endAngle:(M_PI + M_PI_2) clockwise:YES];
757 |
758 | CAShapeLayer *slice = [CAShapeLayer layer];
759 | slice.contentsScale = [[UIScreen mainScreen] scale];
760 | slice.frame = CGRectMake(center.x-radius, center.y-radius, radius*2, radius*2);
761 | slice.fillColor = [UIColor clearColor].CGColor;
762 | slice.strokeColor = color.CGColor;
763 | slice.lineWidth = lineWidth;
764 | slice.lineCap = kCALineCapRound;
765 | slice.lineJoin = kCALineJoinBevel;
766 | slice.path = smoothedPath.CGPath;
767 | return slice;
768 | }
769 |
770 | #pragma mark - Utilities
771 |
772 | + (BOOL)isVisible {
773 | return ([self sharedView].alpha == 1);
774 | }
775 |
776 |
777 | #pragma mark - Getters
778 |
779 | - (NSTimeInterval)displayDurationForString:(NSString*)string {
780 | return MIN((float)string.length*0.06 + 0.3, 5.0);
781 | }
782 |
783 | - (BOOL)isClear { // used for iOS 7
784 | return (self.maskType == SVProgressHUDMaskTypeClear || self.maskType == SVProgressHUDMaskTypeNone);
785 | }
786 |
787 | - (UIControl *)overlayView {
788 | if(!_overlayView) {
789 | _overlayView = [[UIControl alloc] initWithFrame:[UIScreen mainScreen].bounds];
790 | _overlayView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
791 | _overlayView.backgroundColor = [UIColor clearColor];
792 | [_overlayView addTarget:self action:@selector(overlayViewDidReceiveTouchEvent:forEvent:) forControlEvents:UIControlEventTouchDown];
793 | }
794 | return _overlayView;
795 | }
796 |
797 | - (UIView *)hudView {
798 | if(!_hudView) {
799 | _hudView = [[UIView alloc] initWithFrame:CGRectZero];
800 | _hudView.backgroundColor = SVProgressHUDBackgroundColor;
801 | _hudView.layer.cornerRadius = 14;
802 | _hudView.layer.masksToBounds = YES;
803 |
804 | _hudView.autoresizingMask = (UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin |
805 | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin);
806 |
807 | if ([_hudView respondsToSelector:@selector(addMotionEffect:)]) {
808 | UIInterpolatingMotionEffect *effectX = [[UIInterpolatingMotionEffect alloc] initWithKeyPath: @"center.x" type: UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
809 | effectX.minimumRelativeValue = @(-SVProgressHUDParallaxDepthPoints);
810 | effectX.maximumRelativeValue = @(SVProgressHUDParallaxDepthPoints);
811 |
812 | UIInterpolatingMotionEffect *effectY = [[UIInterpolatingMotionEffect alloc] initWithKeyPath: @"center.y" type: UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
813 | effectY.minimumRelativeValue = @(-SVProgressHUDParallaxDepthPoints);
814 | effectY.maximumRelativeValue = @(SVProgressHUDParallaxDepthPoints);
815 |
816 | [_hudView addMotionEffect: effectX];
817 | [_hudView addMotionEffect: effectY];
818 | }
819 |
820 | [self addSubview:_hudView];
821 | }
822 | return _hudView;
823 | }
824 |
825 | - (UILabel *)stringLabel {
826 | if (_stringLabel == nil) {
827 | _stringLabel = [[UILabel alloc] initWithFrame:CGRectZero];
828 | _stringLabel.backgroundColor = [UIColor clearColor];
829 | _stringLabel.adjustsFontSizeToFitWidth = YES;
830 | _stringLabel.textAlignment = NSTextAlignmentCenter;
831 | _stringLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
832 | _stringLabel.textColor = SVProgressHUDForegroundColor;
833 | _stringLabel.font = SVProgressHUDFont;
834 | _stringLabel.numberOfLines = 0;
835 | }
836 |
837 | if(!_stringLabel.superview)
838 | [self.hudView addSubview:_stringLabel];
839 |
840 | return _stringLabel;
841 | }
842 |
843 | - (UIImageView *)imageView {
844 | if (_imageView == nil)
845 | _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 28, 28)];
846 |
847 | if(!_imageView.superview)
848 | [self.hudView addSubview:_imageView];
849 |
850 | return _imageView;
851 | }
852 |
853 |
854 | - (CGFloat)visibleKeyboardHeight {
855 |
856 | UIWindow *keyboardWindow = nil;
857 | for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
858 | if(![[testWindow class] isEqual:[UIWindow class]]) {
859 | keyboardWindow = testWindow;
860 | break;
861 | }
862 | }
863 |
864 | for (__strong UIView *possibleKeyboard in [keyboardWindow subviews]) {
865 | if([possibleKeyboard isKindOfClass:NSClassFromString(@"UIPeripheralHostView")] || [possibleKeyboard isKindOfClass:NSClassFromString(@"UIKeyboard")])
866 | return possibleKeyboard.bounds.size.height;
867 | }
868 |
869 | return 0;
870 | }
871 |
872 | @end
873 |
874 | #pragma mark SVIndefiniteAnimatedView
875 |
876 | @interface SVIndefiniteAnimatedView ()
877 |
878 | @property (nonatomic, strong) CAShapeLayer *indefiniteAnimatedLayer;
879 |
880 | @end
881 |
882 | @implementation SVIndefiniteAnimatedView
883 |
884 | - (id)initWithFrame:(CGRect)frame {
885 | if (self = [super initWithFrame:frame]) {
886 | self.strokeThickness = SVProgressHUDRingThickness;
887 | self.radius = SVProgressHUDRingRadius;
888 | self.strokeColor = SVProgressHUDForegroundColor;
889 | }
890 | return self;
891 | }
892 |
893 | - (void)willMoveToSuperview:(UIView *)newSuperview {
894 | if (newSuperview != nil) {
895 | [self layoutAnimatedLayer];
896 | }
897 | else {
898 | [_indefiniteAnimatedLayer removeFromSuperlayer];
899 | _indefiniteAnimatedLayer = nil;
900 | }
901 | }
902 |
903 | - (void)layoutAnimatedLayer {
904 | CALayer *layer = self.indefiniteAnimatedLayer;
905 |
906 | [self.layer addSublayer:layer];
907 | layer.position = CGPointMake(self.bounds.size.width - layer.bounds.size.width / 2, self.bounds.size.height - layer.bounds.size.height / 2);
908 | }
909 |
910 | - (CAShapeLayer*)indefiniteAnimatedLayer {
911 | if(!_indefiniteAnimatedLayer) {
912 | CGPoint arcCenter = CGPointMake(self.radius+self.strokeThickness/2+5, self.radius+self.strokeThickness/2+5);
913 | CGRect rect = CGRectMake(0, 0, arcCenter.x*2, arcCenter.y*2);
914 |
915 | UIBezierPath* smoothedPath = [UIBezierPath bezierPathWithArcCenter:arcCenter
916 | radius:self.radius
917 | startAngle:M_PI*3/2
918 | endAngle:M_PI/2+M_PI*5
919 | clockwise:YES];
920 |
921 | _indefiniteAnimatedLayer = [CAShapeLayer layer];
922 | _indefiniteAnimatedLayer.contentsScale = [[UIScreen mainScreen] scale];
923 | _indefiniteAnimatedLayer.frame = rect;
924 | _indefiniteAnimatedLayer.fillColor = [UIColor clearColor].CGColor;
925 | _indefiniteAnimatedLayer.strokeColor = self.strokeColor.CGColor;
926 | _indefiniteAnimatedLayer.lineWidth = self.strokeThickness;
927 | _indefiniteAnimatedLayer.lineCap = kCALineCapRound;
928 | _indefiniteAnimatedLayer.lineJoin = kCALineJoinBevel;
929 | _indefiniteAnimatedLayer.path = smoothedPath.CGPath;
930 |
931 | CALayer *maskLayer = [CALayer layer];
932 | maskLayer.contents = (id)[[UIImage imageNamed:@"SVProgressHUD.bundle/angle-mask@2x.png"] CGImage];
933 | maskLayer.frame = _indefiniteAnimatedLayer.bounds;
934 | _indefiniteAnimatedLayer.mask = maskLayer;
935 |
936 | NSTimeInterval animationDuration = 1;
937 | CAMediaTimingFunction *linearCurve = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
938 |
939 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
940 | animation.fromValue = 0;
941 | animation.toValue = [NSNumber numberWithFloat:M_PI*2];
942 | animation.duration = animationDuration;
943 | animation.timingFunction = linearCurve;
944 | animation.removedOnCompletion = NO;
945 | animation.repeatCount = INFINITY;
946 | animation.fillMode = kCAFillModeForwards;
947 | animation.autoreverses = NO;
948 | [_indefiniteAnimatedLayer.mask addAnimation:animation forKey:@"rotate"];
949 |
950 | CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
951 | animationGroup.duration = animationDuration;
952 | animationGroup.repeatCount = INFINITY;
953 | animationGroup.removedOnCompletion = NO;
954 | animationGroup.timingFunction = linearCurve;
955 |
956 | CABasicAnimation *strokeStartAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
957 | strokeStartAnimation.fromValue = @0.015;
958 | strokeStartAnimation.toValue = @0.515;
959 |
960 | CABasicAnimation *strokeEndAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
961 | strokeEndAnimation.fromValue = @0.485;
962 | strokeEndAnimation.toValue = @0.985;
963 |
964 | animationGroup.animations = @[strokeStartAnimation, strokeEndAnimation];
965 | [_indefiniteAnimatedLayer addAnimation:animationGroup forKey:@"progress"];
966 |
967 | }
968 | return _indefiniteAnimatedLayer;
969 | }
970 |
971 | - (void)setFrame:(CGRect)frame {
972 | [super setFrame:frame];
973 |
974 | if (self.superview != nil) {
975 | [self layoutAnimatedLayer];
976 | }
977 | }
978 |
979 | - (void)setRadius:(CGFloat)radius {
980 | _radius = radius;
981 |
982 | [_indefiniteAnimatedLayer removeFromSuperlayer];
983 | _indefiniteAnimatedLayer = nil;
984 |
985 | [self layoutAnimatedLayer];
986 | }
987 |
988 | - (void)setStrokeColor:(UIColor *)strokeColor {
989 | _strokeColor = strokeColor;
990 | _indefiniteAnimatedLayer.strokeColor = strokeColor.CGColor;
991 | }
992 |
993 | - (void)setStrokeThickness:(CGFloat)strokeThickness {
994 | _strokeThickness = strokeThickness;
995 | _indefiniteAnimatedLayer.lineWidth = _strokeThickness;
996 | }
997 |
998 | - (CGSize)sizeThatFits:(CGSize)size {
999 | return CGSizeMake((self.radius+self.strokeThickness/2+5)*2, (self.radius+self.strokeThickness/2+5)*2);
1000 | }
1001 |
1002 | @end
1003 |
--------------------------------------------------------------------------------