├── ExpandScrollViewDemo
├── ExpandScrollViewDemo.xcodeproj
│ ├── project.xcworkspace
│ │ └── contents.xcworkspacedata
│ ├── xcuserdata
│ │ └── aniloruc.xcuserdatad
│ │ │ └── xcschemes
│ │ │ ├── xcschememanagement.plist
│ │ │ └── ExpandScrollViewDemo.xcscheme
│ └── project.pbxproj
└── ExpandScrollViewDemo
│ ├── ViewController.h
│ ├── AppDelegate.h
│ ├── main.m
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
│ ├── Info.plist
│ ├── Base.lproj
│ ├── Main.storyboard
│ └── LaunchScreen.storyboard
│ ├── AppDelegate.m
│ ├── ExpandScrollView
│ ├── ANWExpandScrollView.h
│ ├── ANWExpandScrollView.xib
│ └── ANWExpandScrollView.m
│ └── ViewController.m
├── LICENSE.md
├── ExpandScrollView
├── ANWExpandScrollView.h
├── ANWExpandScrollView.xib
└── ANWExpandScrollView.m
└── README.md
/ExpandScrollViewDemo/ExpandScrollViewDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // ExpandScrollViewDemo
4 | //
5 | // Created by Anil Oruc on 3/10/16.
6 | // Copyright © 2016 Anil Oruc. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // ExpandScrollViewDemo
4 | //
5 | // Created by Anil Oruc on 3/10/16.
6 | // Copyright © 2016 Anil Oruc. 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 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // ExpandScrollViewDemo
4 | //
5 | // Created by Anil Oruc on 3/10/16.
6 | // Copyright © 2016 Anil Oruc. 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 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo.xcodeproj/xcuserdata/aniloruc.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | ExpandScrollViewDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | D3A569891C917112002A1A8C
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo/Assets.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 | }
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Anıl ORUÇ
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 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
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 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo/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 |
27 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo/Base.lproj/LaunchScreen.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 |
27 |
28 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // ExpandScrollViewDemo
4 | //
5 | // Created by Anil Oruc on 3/10/16.
6 | // Copyright © 2016 Anil Oruc. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 | - (void)applicationWillResignActive:(UIApplication *)application {
24 | // 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.
25 | // 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.
26 | }
27 |
28 | - (void)applicationDidEnterBackground:(UIApplication *)application {
29 | // 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.
30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
31 | }
32 |
33 | - (void)applicationWillEnterForeground:(UIApplication *)application {
34 | // 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.
35 | }
36 |
37 | - (void)applicationDidBecomeActive:(UIApplication *)application {
38 | // 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.
39 | }
40 |
41 | - (void)applicationWillTerminate:(UIApplication *)application {
42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 | }
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/ExpandScrollView/ANWExpandScrollView.h:
--------------------------------------------------------------------------------
1 | //
2 | // ANWExpandScrollView.h
3 | // OmsaTech
4 | //
5 | // Created by Anil Oruc on 7/23/15.
6 | // Copyright (c) 2015 OmsaTech. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | typedef enum
12 | {
13 | ANWExpandScrollViewStatusExpand = 0,
14 | ANWExpandScrollViewStatusCollapse,
15 | ANWExpandScrollViewStatusPinching
16 | }
17 | ANWExpandScrollViewStatus;
18 |
19 | @class ANWExpandScrollView;
20 |
21 | @protocol ANWExpandScrollViewDelegate
22 |
23 | @optional
24 |
25 | -(void)expandScrollView:(ANWExpandScrollView*)scrollView changedStatus:(ANWExpandScrollViewStatus)status previousStatus:(ANWExpandScrollViewStatus)previousStatus;
26 |
27 | -(void)expandScrollView:(ANWExpandScrollView*)scrollView didSelectItemAtIndex:(NSUInteger)index;
28 |
29 | // Default value: [UIScreen mainScreen].bounds.size.height
30 | -(CGFloat)expandHeightInScrollView:(ANWExpandScrollView *)scrollView index:(NSUInteger)index;
31 |
32 | // Default value: 44.0f
33 | -(CGFloat)collapseHeightInScrollView:(ANWExpandScrollView *)scrollView index:(NSUInteger)index;
34 |
35 | @end
36 |
37 | @protocol ANWExpandScrollViewDataSource
38 |
39 | @required
40 |
41 | -(UIView*)expandScrollView:(ANWExpandScrollView *)scrollView viewForItemAtIndex:(NSUInteger)index;
42 |
43 | -(NSUInteger)numberOfItemsInScrollView:(ANWExpandScrollView *)scrollView;
44 |
45 | @end
46 |
47 | @interface ANWExpandScrollView : UIView
48 |
49 | + (instancetype)init;
50 |
51 | + (instancetype)initWithFrame:(CGRect)frame;
52 |
53 | @property (nonatomic, weak) IBOutlet id dataSource;
54 |
55 | @property (nonatomic, weak) IBOutlet id delegate;
56 |
57 | @property (nonatomic, assign, readonly) BOOL isExpand;
58 |
59 | // Default value: NO
60 | @property (nonatomic, assign) BOOL scrollEnabledExpand;
61 |
62 | // Default value: YES
63 | @property (nonatomic, assign) BOOL scrollEnabledCollapse;
64 |
65 | @property (nonatomic, assign, readonly) ANWExpandScrollViewStatus status;
66 |
67 | // Default value: Expanding Status: Current Item Index - Collapse Status: Top Item Index
68 | @property (nonatomic, assign, readonly) NSUInteger currentPageIndex;
69 |
70 | -(UIView*)visibleItemAtIndex:(NSUInteger)index;
71 |
72 | @property (nonatomic, strong, readonly) NSArray *visibleItemIndexs;
73 |
74 | - (void)expandAtIndex:(NSInteger)index animated:(BOOL)animated;
75 |
76 | - (void)collapseWithAnimated:(BOOL)animated;
77 |
78 | - (void)reloadData;
79 |
80 | @end
81 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo/ExpandScrollView/ANWExpandScrollView.h:
--------------------------------------------------------------------------------
1 | //
2 | // ANWExpandScrollView.h
3 | // OmsaTech
4 | //
5 | // Created by Anil Oruc on 7/23/15.
6 | // Copyright (c) 2015 OmsaTech. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | typedef enum
12 | {
13 | ANWExpandScrollViewStatusExpand = 0,
14 | ANWExpandScrollViewStatusCollapse,
15 | ANWExpandScrollViewStatusPinching
16 | }
17 | ANWExpandScrollViewStatus;
18 |
19 | @class ANWExpandScrollView;
20 |
21 | @protocol ANWExpandScrollViewDelegate
22 |
23 | @optional
24 |
25 | -(void)expandScrollView:(ANWExpandScrollView*)scrollView changedStatus:(ANWExpandScrollViewStatus)status previousStatus:(ANWExpandScrollViewStatus)previousStatus;
26 |
27 | -(void)expandScrollView:(ANWExpandScrollView*)scrollView didSelectItemAtIndex:(NSUInteger)index;
28 |
29 | // Default value: [UIScreen mainScreen].bounds.size.height
30 | -(CGFloat)expandHeightInScrollView:(ANWExpandScrollView *)scrollView index:(NSUInteger)index;
31 |
32 | // Default value: 44.0f
33 | -(CGFloat)collapseHeightInScrollView:(ANWExpandScrollView *)scrollView index:(NSUInteger)index;
34 |
35 | @end
36 |
37 | @protocol ANWExpandScrollViewDataSource
38 |
39 | @required
40 |
41 | -(UIView*)expandScrollView:(ANWExpandScrollView *)scrollView viewForItemAtIndex:(NSUInteger)index;
42 |
43 | -(NSUInteger)numberOfItemsInScrollView:(ANWExpandScrollView *)scrollView;
44 |
45 | @end
46 |
47 | @interface ANWExpandScrollView : UIView
48 |
49 | + (instancetype)init;
50 |
51 | + (instancetype)initWithFrame:(CGRect)frame;
52 |
53 | @property (nonatomic, weak) IBOutlet id dataSource;
54 |
55 | @property (nonatomic, weak) IBOutlet id delegate;
56 |
57 | @property (nonatomic, assign, readonly) BOOL isExpand;
58 |
59 | // Default value: NO
60 | @property (nonatomic, assign) BOOL scrollEnabledExpand;
61 |
62 | // Default value: YES
63 | @property (nonatomic, assign) BOOL scrollEnabledCollapse;
64 |
65 | @property (nonatomic, assign, readonly) ANWExpandScrollViewStatus status;
66 |
67 | // Default value: Expanding Status: Current Item Index - Collapse Status: Top Item Index
68 | @property (nonatomic, assign, readonly) NSUInteger currentPageIndex;
69 |
70 | -(UIView*)visibleItemAtIndex:(NSUInteger)index;
71 |
72 | @property (nonatomic, strong, readonly) NSArray *visibleItemIndexs;
73 |
74 | - (void)expandAtIndex:(NSInteger)index animated:(BOOL)animated;
75 |
76 | - (void)collapseWithAnimated:(BOOL)animated;
77 |
78 | - (void)reloadData;
79 |
80 | @end
81 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // ExpandScrollViewDemo
4 | //
5 | // Created by Anil Oruc on 3/10/16.
6 | // Copyright © 2016 Anil Oruc. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 | #import "ANWExpandScrollView.h"
11 |
12 | @interface ViewController ()
13 |
14 | @property (nonatomic,strong) NSArray *colors;
15 |
16 | @end
17 |
18 | @implementation ViewController
19 |
20 | - (void)viewDidLoad {
21 | [super viewDidLoad];
22 | // Do any additional setup after loading the view, typically from a nib.
23 |
24 | _colors = @[[self randomColor],[self randomColor],[self randomColor],[self randomColor],[self randomColor],[self randomColor],[self randomColor],[self randomColor],[self randomColor],[self randomColor],[self randomColor]];
25 |
26 | ANWExpandScrollView *scrollView = [ANWExpandScrollView initWithFrame:[UIScreen mainScreen].bounds];
27 | scrollView.delegate = self;
28 | scrollView.dataSource = self;
29 |
30 | [scrollView reloadData];
31 |
32 | [scrollView expandAtIndex:0 animated:NO];
33 |
34 | [self.view addSubview:scrollView];
35 | }
36 |
37 | - (void)didReceiveMemoryWarning {
38 | [super didReceiveMemoryWarning];
39 | // Dispose of any resources that can be recreated.
40 | }
41 |
42 | -(UIColor*)randomColor
43 | {
44 | CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
45 | CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
46 | CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
47 | UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
48 | return color;
49 | }
50 |
51 | #pragma mark - ANWExpandScrollView delegates & datasources
52 |
53 | -(NSUInteger)numberOfItemsInScrollView:(ANWExpandScrollView *)scrollView
54 | {
55 | return _colors.count;
56 | }
57 |
58 | -(UIView *)expandScrollView:(ANWExpandScrollView *)scrollView viewForItemAtIndex:(NSUInteger)index
59 | {
60 | UIView * view = [UIView new];
61 |
62 | view.backgroundColor = _colors[index];
63 |
64 | return view;
65 | }
66 |
67 | -(void)expandScrollView:(ANWExpandScrollView *)scrollView didSelectItemAtIndex:(NSUInteger)index
68 | {
69 |
70 | }
71 |
72 | -(CGFloat)collapseHeightInScrollView:(ANWExpandScrollView *)scrollView index:(NSUInteger)index
73 | {
74 | return 160.0f;
75 | }
76 |
77 | -(void)expandScrollView:(ANWExpandScrollView *)scrollView changedStatus:(ANWExpandScrollViewStatus)status previousStatus:(ANWExpandScrollViewStatus)previousStatus
78 | {
79 | // Show Animation
80 | }
81 |
82 | @end
83 |
--------------------------------------------------------------------------------
/ExpandScrollView/ANWExpandScrollView.xib:
--------------------------------------------------------------------------------
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 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo/ExpandScrollView/ANWExpandScrollView.xib:
--------------------------------------------------------------------------------
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 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo.xcodeproj/xcuserdata/aniloruc.xcuserdatad/xcschemes/ExpandScrollViewDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ExpandScrollView
2 | Expand - Collapse Scroll View - Animate With Pinch Gesture
3 |
4 | The component was used in the platinum application : https://itunes.apple.com/tr/app/turkcell-platinum-size-ozel/id671494224?mt=8
5 |
6 | ## Display Visual Example
7 |
8 | ----
9 | 
10 |
11 |
12 | Installation
13 | --------------
14 |
15 | To use the PLExpandScrollView class in an app, just drag the PLExpandScrollView class files (demo files and assets are not needed) into your project.
16 |
17 | Properties
18 | --------------
19 |
20 | The PLExpandScrollView has the following properties (note: for iOS, UIView when using properties):
21 |
22 | @property (nonatomic, weak) IBOutlet id dataSource;
23 |
24 | An object that supports the PLExpandScrollViewDataSource protocol and can provide views to populate the scroll.
25 |
26 | @property (nonatomic, weak) IBOutlet id delegate;
27 |
28 | An object that supports the PLExpandScrollViewDelegate protocol and can respond to scroll events and layout requests.
29 |
30 | @property (nonatomic, assign, readonly) BOOL isExpand;
31 |
32 | Returns the scroll is currently being state programatically.
33 |
34 | @property (nonatomic, assign) BOOL scrollEnabledExpand;
35 |
36 | Enables and disables user scrolling on expand state of the scroll. The scroll can still be scrolled programmatically on expand state if this property is set to NO.
37 |
38 | @property (nonatomic, assign) BOOL scrollEnabledCollapse;
39 |
40 | Enables and disables user scrolling on collapse state of the scroll. The scroll can still be scrolled programmatically on collapse state if this property is set to YES.
41 |
42 | @property (nonatomic, assign, readonly) PLExpandScrollViewStatus status;
43 |
44 | Returns the scroll is currently being status programatically. (PLExpandScrollViewStatusExpand, PLExpandScrollViewStatusCollapse or PLExpandScrollViewStatusPinching)
45 |
46 | @property (nonatomic, assign, readonly) NSUInteger currentPageIndex;
47 |
48 | Returns the scroll is currently being page index programatically. Expanding Status: Current Item Index - Collapse Status: Top Item Index.
49 |
50 | @property (nonatomic, strong, readonly) NSArray *visibleItemIndexs;
51 |
52 | An array containing the indexes of only visible item views currently loaded and visible in the scroll. The array contains NSNumber objects whose integer values match the indexes of the views. The indexes for item views start at zero and match the indexes passed to the dataSource to load the view, however the indexes not equal to numberOfItems.
53 |
54 |
55 | Methods
56 | --------------
57 |
58 | The PLExpandScrollView class has the following methods (note: for iOS, UIView in method arguments):
59 |
60 | + (instancetype)init;
61 |
62 | Custom initialize method.
63 |
64 | + (instancetype)initWithFrame:(CGRect)frame;
65 |
66 | Custom initialize method.
67 |
68 | - (UIView*)visibleItemAtIndex:(NSUInteger)index;
69 |
70 | Returns the visible item view with the specified index. Note that the index relates to the position in the scroll, and not the position in the visibleItemIndexs array, which may be different. Pass a negative index or one greater than or equal to numberOfItems to retrieve placeholder views. The method only works for visible item views and will return nil if the view at the specified index has not been loaded, or if the index is out of bounds.
71 |
72 | - (void)expandAtIndex:(NSInteger)index animated:(BOOL)animated;
73 |
74 | This will center the scroll expand on the specified item, either immediately or with a smooth animation.
75 |
76 | - (void)collapseWithAnimated:(BOOL)animated;
77 |
78 | This will top the scroll collapse on the specified item, either immediately or with a smooth animation.
79 |
80 | - (void)reloadData;
81 |
82 | This reloads all scroll views from the dataSource and refreshes the scroll display.
83 |
84 |
85 | Protocols
86 | --------------
87 |
88 | The PLExpandScrollView follows the Apple convention for data-driven views by providing two protocol interfaces, PLExpandScrollViewDataSource and PLExpandScrollViewDelegate. The PLExpandScrollViewDataSource protocol has the following required methods (note: for iOS, UIView in method arguments):
89 |
90 | -(NSUInteger)numberOfItemsInScrollView:(PLExpandScrollView *)scrollView;
91 |
92 | Return the number of items (views) in the scroll.
93 |
94 | -(UIView*)expandScrollView:(PLExpandScrollView *)scrollView viewForItemAtIndex:(NSUInteger)index;
95 |
96 | Return a view to be displayed at the specified index in the scroll.
97 |
98 | The PLExpandScrollViewDelegate protocol has the following optional methods:
99 |
100 | -(void)expandScrollView:(PLExpandScrollView*)scrollView didSelectItemAtIndex:(NSUInteger)index;
101 |
102 | This method will fire if the user taps any scroll item view, including the currently selected view. This method will not fire if the user taps a control within the currently selected view (i.e. any view that is a subclass of UIControl).
103 |
104 | -(void)expandScrollView:(PLExpandScrollView*)scrollView changedStatus:(PLExpandScrollViewStatus)status previousStatus:(PLExpandScrollViewStatus)previousStatus;
105 |
106 | This method is called whenever the scroll scrolls far enough for the currentItemIndex property to change. It is called regardless of whether the item index was updated programatically or through user interaction.
107 |
108 | -(CGFloat)expandHeightInScrollView:(PLExpandScrollView *)scrollView index:(NSUInteger)index;
109 |
110 | This method is called whenever the scroll change status far enough for the currentItemIndex property to change. It is called regardless of whether the item index was updated programatically or through user interaction. The scroll can still be scrolled programmatically on expand state if this property is set to [UIScreen mainScreen].bounds.size.height.
111 |
112 | -(CGFloat)collapseHeightInScrollView:(PLExpandScrollView *)scrollView index:(NSUInteger)index;
113 |
114 | This method is called whenever the scroll change status far enough for the currentItemIndex property to change. It is called regardless of whether the item index was updated programatically or through user interaction. The scroll can still be scrolled programmatically on collapse state if this property is set to 44.0f.
115 |
116 |
117 | How to use ?
118 | ----------
119 |
120 | ```Objective-C
121 | #import "PLExpandScrollView.h"
122 |
123 | @interface ViewController ()
124 |
125 | ...
126 |
127 | - (void)loadView
128 | {
129 | [super loadView];
130 |
131 | PLExpandScrollView *scrollView = [PLExpandScrollView initWithFrame:[UIScreen mainScreen].bounds];
132 | scrollView.delegate = self;
133 | scrollView.dataSource = self;
134 |
135 | [scrollView reloadData];
136 |
137 | [scrollView expandAtIndex:0 animated:NO];
138 |
139 | }
140 |
141 | ...
142 |
143 | #pragma mark - PLExpandScrollView delegates & datasources
144 |
145 | -(NSUInteger)numberOfItemsInScrollView:(PLExpandScrollView *)scrollView
146 | {
147 | return 10;
148 | }
149 |
150 | -(UIView *)expandScrollView:(PLExpandScrollView *)scrollView viewForItemAtIndex:(NSUInteger)index
151 | {
152 | return [UIView new];
153 | }
154 |
155 | -(void)expandScrollView:(PLExpandScrollView *)scrollView didSelectItemAtIndex:(NSUInteger)index
156 | {
157 |
158 | }
159 |
160 | -(CGFloat)collapseHeightInScrollView:(PLExpandScrollView *)scrollView index:(NSUInteger)index
161 | {
162 | return 160.0f;
163 | }
164 |
165 | -(void)expandScrollView:(PLExpandScrollView *)scrollView changedStatus:(PLExpandScrollViewStatus)status previousStatus:(PLExpandScrollViewStatus)previousStatus
166 | {
167 | // Show Animation
168 | }
169 |
170 | ```
171 |
172 | Build and run the project files. Enjoy more examples!
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | D3A5698F1C917112002A1A8C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D3A5698E1C917112002A1A8C /* main.m */; };
11 | D3A569921C917112002A1A8C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D3A569911C917112002A1A8C /* AppDelegate.m */; };
12 | D3A569951C917112002A1A8C /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D3A569941C917112002A1A8C /* ViewController.m */; };
13 | D3A569981C917112002A1A8C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D3A569961C917112002A1A8C /* Main.storyboard */; };
14 | D3A5699A1C917112002A1A8C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D3A569991C917112002A1A8C /* Assets.xcassets */; };
15 | D3A5699D1C917112002A1A8C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D3A5699B1C917112002A1A8C /* LaunchScreen.storyboard */; };
16 | D3A569A81C917135002A1A8C /* ANWExpandScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = D3A569A61C917135002A1A8C /* ANWExpandScrollView.m */; };
17 | D3A569A91C917135002A1A8C /* ANWExpandScrollView.xib in Resources */ = {isa = PBXBuildFile; fileRef = D3A569A71C917135002A1A8C /* ANWExpandScrollView.xib */; };
18 | /* End PBXBuildFile section */
19 |
20 | /* Begin PBXFileReference section */
21 | D3A5698A1C917112002A1A8C /* ExpandScrollViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ExpandScrollViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
22 | D3A5698E1C917112002A1A8C /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
23 | D3A569901C917112002A1A8C /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
24 | D3A569911C917112002A1A8C /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
25 | D3A569931C917112002A1A8C /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; };
26 | D3A569941C917112002A1A8C /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; };
27 | D3A569971C917112002A1A8C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
28 | D3A569991C917112002A1A8C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
29 | D3A5699C1C917112002A1A8C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
30 | D3A5699E1C917112002A1A8C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
31 | D3A569A51C917135002A1A8C /* ANWExpandScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANWExpandScrollView.h; sourceTree = ""; };
32 | D3A569A61C917135002A1A8C /* ANWExpandScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANWExpandScrollView.m; sourceTree = ""; };
33 | D3A569A71C917135002A1A8C /* ANWExpandScrollView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ANWExpandScrollView.xib; sourceTree = ""; };
34 | /* End PBXFileReference section */
35 |
36 | /* Begin PBXFrameworksBuildPhase section */
37 | D3A569871C917112002A1A8C /* Frameworks */ = {
38 | isa = PBXFrameworksBuildPhase;
39 | buildActionMask = 2147483647;
40 | files = (
41 | );
42 | runOnlyForDeploymentPostprocessing = 0;
43 | };
44 | /* End PBXFrameworksBuildPhase section */
45 |
46 | /* Begin PBXGroup section */
47 | D3A569811C917112002A1A8C = {
48 | isa = PBXGroup;
49 | children = (
50 | D3A5698C1C917112002A1A8C /* ExpandScrollViewDemo */,
51 | D3A5698B1C917112002A1A8C /* Products */,
52 | );
53 | sourceTree = "";
54 | };
55 | D3A5698B1C917112002A1A8C /* Products */ = {
56 | isa = PBXGroup;
57 | children = (
58 | D3A5698A1C917112002A1A8C /* ExpandScrollViewDemo.app */,
59 | );
60 | name = Products;
61 | sourceTree = "";
62 | };
63 | D3A5698C1C917112002A1A8C /* ExpandScrollViewDemo */ = {
64 | isa = PBXGroup;
65 | children = (
66 | D3A569A41C917135002A1A8C /* ExpandScrollView */,
67 | D3A569901C917112002A1A8C /* AppDelegate.h */,
68 | D3A569911C917112002A1A8C /* AppDelegate.m */,
69 | D3A569931C917112002A1A8C /* ViewController.h */,
70 | D3A569941C917112002A1A8C /* ViewController.m */,
71 | D3A569961C917112002A1A8C /* Main.storyboard */,
72 | D3A569991C917112002A1A8C /* Assets.xcassets */,
73 | D3A5699B1C917112002A1A8C /* LaunchScreen.storyboard */,
74 | D3A5699E1C917112002A1A8C /* Info.plist */,
75 | D3A5698D1C917112002A1A8C /* Supporting Files */,
76 | );
77 | path = ExpandScrollViewDemo;
78 | sourceTree = "";
79 | };
80 | D3A5698D1C917112002A1A8C /* Supporting Files */ = {
81 | isa = PBXGroup;
82 | children = (
83 | D3A5698E1C917112002A1A8C /* main.m */,
84 | );
85 | name = "Supporting Files";
86 | sourceTree = "";
87 | };
88 | D3A569A41C917135002A1A8C /* ExpandScrollView */ = {
89 | isa = PBXGroup;
90 | children = (
91 | D3A569A51C917135002A1A8C /* ANWExpandScrollView.h */,
92 | D3A569A61C917135002A1A8C /* ANWExpandScrollView.m */,
93 | D3A569A71C917135002A1A8C /* ANWExpandScrollView.xib */,
94 | );
95 | path = ExpandScrollView;
96 | sourceTree = "";
97 | };
98 | /* End PBXGroup section */
99 |
100 | /* Begin PBXNativeTarget section */
101 | D3A569891C917112002A1A8C /* ExpandScrollViewDemo */ = {
102 | isa = PBXNativeTarget;
103 | buildConfigurationList = D3A569A11C917112002A1A8C /* Build configuration list for PBXNativeTarget "ExpandScrollViewDemo" */;
104 | buildPhases = (
105 | D3A569861C917112002A1A8C /* Sources */,
106 | D3A569871C917112002A1A8C /* Frameworks */,
107 | D3A569881C917112002A1A8C /* Resources */,
108 | );
109 | buildRules = (
110 | );
111 | dependencies = (
112 | );
113 | name = ExpandScrollViewDemo;
114 | productName = ExpandScrollViewDemo;
115 | productReference = D3A5698A1C917112002A1A8C /* ExpandScrollViewDemo.app */;
116 | productType = "com.apple.product-type.application";
117 | };
118 | /* End PBXNativeTarget section */
119 |
120 | /* Begin PBXProject section */
121 | D3A569821C917112002A1A8C /* Project object */ = {
122 | isa = PBXProject;
123 | attributes = {
124 | LastUpgradeCheck = 0720;
125 | ORGANIZATIONNAME = "Anil Oruc";
126 | TargetAttributes = {
127 | D3A569891C917112002A1A8C = {
128 | CreatedOnToolsVersion = 7.2.1;
129 | };
130 | };
131 | };
132 | buildConfigurationList = D3A569851C917112002A1A8C /* Build configuration list for PBXProject "ExpandScrollViewDemo" */;
133 | compatibilityVersion = "Xcode 3.2";
134 | developmentRegion = English;
135 | hasScannedForEncodings = 0;
136 | knownRegions = (
137 | en,
138 | Base,
139 | );
140 | mainGroup = D3A569811C917112002A1A8C;
141 | productRefGroup = D3A5698B1C917112002A1A8C /* Products */;
142 | projectDirPath = "";
143 | projectRoot = "";
144 | targets = (
145 | D3A569891C917112002A1A8C /* ExpandScrollViewDemo */,
146 | );
147 | };
148 | /* End PBXProject section */
149 |
150 | /* Begin PBXResourcesBuildPhase section */
151 | D3A569881C917112002A1A8C /* Resources */ = {
152 | isa = PBXResourcesBuildPhase;
153 | buildActionMask = 2147483647;
154 | files = (
155 | D3A5699D1C917112002A1A8C /* LaunchScreen.storyboard in Resources */,
156 | D3A569A91C917135002A1A8C /* ANWExpandScrollView.xib in Resources */,
157 | D3A5699A1C917112002A1A8C /* Assets.xcassets in Resources */,
158 | D3A569981C917112002A1A8C /* Main.storyboard in Resources */,
159 | );
160 | runOnlyForDeploymentPostprocessing = 0;
161 | };
162 | /* End PBXResourcesBuildPhase section */
163 |
164 | /* Begin PBXSourcesBuildPhase section */
165 | D3A569861C917112002A1A8C /* Sources */ = {
166 | isa = PBXSourcesBuildPhase;
167 | buildActionMask = 2147483647;
168 | files = (
169 | D3A569951C917112002A1A8C /* ViewController.m in Sources */,
170 | D3A569A81C917135002A1A8C /* ANWExpandScrollView.m in Sources */,
171 | D3A569921C917112002A1A8C /* AppDelegate.m in Sources */,
172 | D3A5698F1C917112002A1A8C /* main.m in Sources */,
173 | );
174 | runOnlyForDeploymentPostprocessing = 0;
175 | };
176 | /* End PBXSourcesBuildPhase section */
177 |
178 | /* Begin PBXVariantGroup section */
179 | D3A569961C917112002A1A8C /* Main.storyboard */ = {
180 | isa = PBXVariantGroup;
181 | children = (
182 | D3A569971C917112002A1A8C /* Base */,
183 | );
184 | name = Main.storyboard;
185 | sourceTree = "";
186 | };
187 | D3A5699B1C917112002A1A8C /* LaunchScreen.storyboard */ = {
188 | isa = PBXVariantGroup;
189 | children = (
190 | D3A5699C1C917112002A1A8C /* Base */,
191 | );
192 | name = LaunchScreen.storyboard;
193 | sourceTree = "";
194 | };
195 | /* End PBXVariantGroup section */
196 |
197 | /* Begin XCBuildConfiguration section */
198 | D3A5699F1C917112002A1A8C /* Debug */ = {
199 | isa = XCBuildConfiguration;
200 | buildSettings = {
201 | ALWAYS_SEARCH_USER_PATHS = NO;
202 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
203 | CLANG_CXX_LIBRARY = "libc++";
204 | CLANG_ENABLE_MODULES = YES;
205 | CLANG_ENABLE_OBJC_ARC = YES;
206 | CLANG_WARN_BOOL_CONVERSION = YES;
207 | CLANG_WARN_CONSTANT_CONVERSION = YES;
208 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
209 | CLANG_WARN_EMPTY_BODY = YES;
210 | CLANG_WARN_ENUM_CONVERSION = YES;
211 | CLANG_WARN_INT_CONVERSION = YES;
212 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
213 | CLANG_WARN_UNREACHABLE_CODE = YES;
214 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
215 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
216 | COPY_PHASE_STRIP = NO;
217 | DEBUG_INFORMATION_FORMAT = dwarf;
218 | ENABLE_STRICT_OBJC_MSGSEND = YES;
219 | ENABLE_TESTABILITY = YES;
220 | GCC_C_LANGUAGE_STANDARD = gnu99;
221 | GCC_DYNAMIC_NO_PIC = NO;
222 | GCC_NO_COMMON_BLOCKS = YES;
223 | GCC_OPTIMIZATION_LEVEL = 0;
224 | GCC_PREPROCESSOR_DEFINITIONS = (
225 | "DEBUG=1",
226 | "$(inherited)",
227 | );
228 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
229 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
230 | GCC_WARN_UNDECLARED_SELECTOR = YES;
231 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
232 | GCC_WARN_UNUSED_FUNCTION = YES;
233 | GCC_WARN_UNUSED_VARIABLE = YES;
234 | IPHONEOS_DEPLOYMENT_TARGET = 9.2;
235 | MTL_ENABLE_DEBUG_INFO = YES;
236 | ONLY_ACTIVE_ARCH = YES;
237 | SDKROOT = iphoneos;
238 | };
239 | name = Debug;
240 | };
241 | D3A569A01C917112002A1A8C /* Release */ = {
242 | isa = XCBuildConfiguration;
243 | buildSettings = {
244 | ALWAYS_SEARCH_USER_PATHS = NO;
245 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
246 | CLANG_CXX_LIBRARY = "libc++";
247 | CLANG_ENABLE_MODULES = YES;
248 | CLANG_ENABLE_OBJC_ARC = YES;
249 | CLANG_WARN_BOOL_CONVERSION = YES;
250 | CLANG_WARN_CONSTANT_CONVERSION = YES;
251 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
252 | CLANG_WARN_EMPTY_BODY = YES;
253 | CLANG_WARN_ENUM_CONVERSION = YES;
254 | CLANG_WARN_INT_CONVERSION = YES;
255 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
256 | CLANG_WARN_UNREACHABLE_CODE = YES;
257 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
258 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
259 | COPY_PHASE_STRIP = NO;
260 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
261 | ENABLE_NS_ASSERTIONS = NO;
262 | ENABLE_STRICT_OBJC_MSGSEND = YES;
263 | GCC_C_LANGUAGE_STANDARD = gnu99;
264 | GCC_NO_COMMON_BLOCKS = YES;
265 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
266 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
267 | GCC_WARN_UNDECLARED_SELECTOR = YES;
268 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
269 | GCC_WARN_UNUSED_FUNCTION = YES;
270 | GCC_WARN_UNUSED_VARIABLE = YES;
271 | IPHONEOS_DEPLOYMENT_TARGET = 9.2;
272 | MTL_ENABLE_DEBUG_INFO = NO;
273 | SDKROOT = iphoneos;
274 | VALIDATE_PRODUCT = YES;
275 | };
276 | name = Release;
277 | };
278 | D3A569A21C917112002A1A8C /* Debug */ = {
279 | isa = XCBuildConfiguration;
280 | buildSettings = {
281 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
282 | INFOPLIST_FILE = ExpandScrollViewDemo/Info.plist;
283 | IPHONEOS_DEPLOYMENT_TARGET = 7.0;
284 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
285 | PRODUCT_BUNDLE_IDENTIFIER = annulmobile.ExpandScrollViewDemo;
286 | PRODUCT_NAME = "$(TARGET_NAME)";
287 | };
288 | name = Debug;
289 | };
290 | D3A569A31C917112002A1A8C /* Release */ = {
291 | isa = XCBuildConfiguration;
292 | buildSettings = {
293 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
294 | INFOPLIST_FILE = ExpandScrollViewDemo/Info.plist;
295 | IPHONEOS_DEPLOYMENT_TARGET = 7.0;
296 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
297 | PRODUCT_BUNDLE_IDENTIFIER = annulmobile.ExpandScrollViewDemo;
298 | PRODUCT_NAME = "$(TARGET_NAME)";
299 | };
300 | name = Release;
301 | };
302 | /* End XCBuildConfiguration section */
303 |
304 | /* Begin XCConfigurationList section */
305 | D3A569851C917112002A1A8C /* Build configuration list for PBXProject "ExpandScrollViewDemo" */ = {
306 | isa = XCConfigurationList;
307 | buildConfigurations = (
308 | D3A5699F1C917112002A1A8C /* Debug */,
309 | D3A569A01C917112002A1A8C /* Release */,
310 | );
311 | defaultConfigurationIsVisible = 0;
312 | defaultConfigurationName = Release;
313 | };
314 | D3A569A11C917112002A1A8C /* Build configuration list for PBXNativeTarget "ExpandScrollViewDemo" */ = {
315 | isa = XCConfigurationList;
316 | buildConfigurations = (
317 | D3A569A21C917112002A1A8C /* Debug */,
318 | D3A569A31C917112002A1A8C /* Release */,
319 | );
320 | defaultConfigurationIsVisible = 0;
321 | defaultConfigurationName = Release;
322 | };
323 | /* End XCConfigurationList section */
324 | };
325 | rootObject = D3A569821C917112002A1A8C /* Project object */;
326 | }
327 |
--------------------------------------------------------------------------------
/ExpandScrollView/ANWExpandScrollView.m:
--------------------------------------------------------------------------------
1 | //
2 | // ANWExpandScrollView.m
3 | // OmsaTech
4 | //
5 | // Created by Anil Oruc on 7/23/15.
6 | // Copyright (c) 2015 OmsaTech. All rights reserved.
7 | //
8 |
9 | #import "ANWExpandScrollView.h"
10 |
11 | #define COLLAPSE_DEFAULTH_HEIGHT 44.0f
12 |
13 | @interface ANWExpandScrollView ()
14 | {
15 | UIPinchGestureRecognizer *pgr;
16 |
17 | NSInteger _indexOfPinchingElement;
18 | CGFloat _initialHeightOfPinchingElement;
19 | CGPoint _offsetTableViewBeforePinching;
20 | UIEdgeInsets _insetTableView;
21 | CGFloat _expandedHeight;
22 | CGFloat _collapsedHeight;
23 |
24 | NSMutableArray *_items;
25 | }
26 |
27 | @property (weak, nonatomic) IBOutlet UITableView *tableView;
28 |
29 | @property (nonatomic, assign) BOOL isExpand;
30 |
31 | @property (nonatomic, assign) NSUInteger currentPageIndex;
32 | @property (nonatomic, assign) CGFloat height;
33 |
34 | @end
35 |
36 | @implementation ANWExpandScrollView
37 |
38 | + (instancetype)init
39 | {
40 | ANWExpandScrollView *view = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil].firstObject;
41 | if (view) {
42 |
43 | [view loadView];
44 | }
45 | return view;
46 | }
47 |
48 | + (instancetype)initWithFrame:(CGRect)frame
49 | {
50 | ANWExpandScrollView *view = [self init];
51 | if (view)
52 | {
53 | [view setFrame:frame];
54 | }
55 | return view;
56 | }
57 |
58 | -(void)setFrame:(CGRect)frame
59 | {
60 | [super setFrame:frame];
61 |
62 | [self setNeedsLayout];
63 | [self layoutIfNeeded];
64 |
65 | }
66 |
67 | -(void)loadView
68 | {
69 | _isExpand = NO;
70 | _scrollEnabledCollapse = YES;
71 | _scrollEnabledExpand = NO;
72 | _currentPageIndex = NSNotFound;
73 | _status = ANWExpandScrollViewStatusCollapse;
74 |
75 | [self addPinchGestureRecognizer];
76 | }
77 |
78 | -(void)addPinchGestureRecognizer
79 | {
80 | [pgr removeTarget:self action:@selector(handlePinch:)];
81 | pgr = nil;
82 | pgr = [[UIPinchGestureRecognizer alloc]
83 | initWithTarget:self action:@selector(handlePinch:)];
84 | pgr.delegate = self;
85 |
86 | [self addGestureRecognizer:pgr];
87 | }
88 |
89 |
90 | - (void)handlePinch:(UIPinchGestureRecognizer *)pinchGestureRecognizer
91 | {
92 | if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan) {
93 | [self onPinchBegan:pinchGestureRecognizer];
94 | }
95 | else if (pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {
96 | [self onPinchChanged:pinchGestureRecognizer];
97 | }
98 | else if ((pinchGestureRecognizer.state == UIGestureRecognizerStateCancelled) || (pinchGestureRecognizer.state == UIGestureRecognizerStateEnded)) {
99 | [self onPinchEnded:pinchGestureRecognizer];
100 | }
101 | }
102 |
103 | - (void)onPinchBegan:(UIPinchGestureRecognizer*)pinchRecognizer
104 | {
105 | _indexOfPinchingElement = NSNotFound;
106 |
107 | CGPoint pinchLocation = [pinchRecognizer locationInView:_tableView];
108 | NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:pinchLocation];
109 |
110 | if (indexPath != nil) {
111 |
112 | self.status = ANWExpandScrollViewStatusPinching;
113 |
114 | _indexOfPinchingElement = indexPath.row;
115 |
116 | _initialHeightOfPinchingElement = _height;
117 | _offsetTableViewBeforePinching = _tableView.contentOffset;
118 |
119 | _tableView.contentInset = UIEdgeInsetsMake(_tableView.frame.size.height, 0.f, _tableView.frame.size.height, 0.f);
120 | }
121 | }
122 |
123 | - (void)onPinchChanged:(UIPinchGestureRecognizer*)pinchRecognizer
124 | {
125 | if (_indexOfPinchingElement == NSNotFound) {
126 | return;
127 | }
128 |
129 | CGFloat newHeight = (_initialHeightOfPinchingElement * pinchRecognizer.scale);
130 |
131 | self.height = newHeight;
132 |
133 | [self updateCellsHeightsAnimated:NO];
134 |
135 | CGFloat diffHeight = newHeight - _initialHeightOfPinchingElement;
136 | CGFloat yOffsetTableView = _offsetTableViewBeforePinching.y + (_indexOfPinchingElement * diffHeight) + (diffHeight / 2.f);
137 | _tableView.contentOffset = CGPointMake(_offsetTableViewBeforePinching.x, yOffsetTableView);
138 |
139 | }
140 |
141 | - (void)onPinchEnded:(UIPinchGestureRecognizer*)pinchRecognizer
142 | {
143 | if (_indexOfPinchingElement == NSNotFound) {
144 | return;
145 | }
146 |
147 | CGPoint offset = _tableView.contentOffset;
148 | _tableView.contentInset = _insetTableView;
149 | _tableView.contentOffset = offset;
150 |
151 | BOOL open = NO;
152 | if (_initialHeightOfPinchingElement > _height) { //open
153 | open = _height > _expandedHeight * 0.8f;
154 | }
155 | else { //close
156 | open = _height > _expandedHeight * 0.2f;
157 | }
158 |
159 | if (open) {
160 | [self expandAtIndex:_indexOfPinchingElement animated:NO];
161 |
162 | }
163 | else {
164 | [self collapseWithAnimated:NO];
165 | }
166 | }
167 |
168 | -(void)setHeight:(CGFloat)height
169 | {
170 | _height = MIN(_expandedHeight, MAX(height, _collapsedHeight));
171 |
172 | [self allCellsHeightChanged];
173 | }
174 |
175 | -(void)allCellsHeightChanged
176 | {
177 | for (UIView *item in _items) {
178 | if ([item isKindOfClass:[UIView class]]) {
179 |
180 | CGRect frame = item.frame;
181 | frame.size.height = _height;
182 | frame.size.width = self.frame.size.width;
183 | [item setFrame:frame];
184 | }
185 | }
186 | }
187 |
188 | - (void)updateCellsHeightsAnimated:(BOOL)animated
189 | {
190 | BOOL animationsEnabled = [UIView areAnimationsEnabled];
191 | [UIView setAnimationsEnabled:animated];
192 | [_tableView beginUpdates];
193 | [_tableView reloadData];
194 | [_tableView endUpdates];
195 | [UIView setAnimationsEnabled:animationsEnabled];
196 | }
197 |
198 | - (void)scrollToTopCellAtIndex:(NSUInteger)index animated:(BOOL)animated
199 | {
200 | @try {
201 |
202 | NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
203 | [_tableView scrollToRowAtIndexPath:([_tableView numberOfRowsInSection:0] > index ? indexPath : [NSIndexPath indexPathForRow:[_tableView numberOfRowsInSection:0]-1 inSection:0]) atScrollPosition:UITableViewScrollPositionTop animated:animated];
204 | }
205 | @catch (NSException *exception) {
206 | [_tableView reloadData];
207 | }
208 | @finally {
209 |
210 | }
211 | }
212 |
213 | - (void)scrollToContentBoundsCellAtIndex:(NSInteger)indexSelected animated:(BOOL)animated
214 | {
215 | CGFloat visibleTableHeight = _tableView.frame.size.height - _insetTableView.top - _insetTableView.bottom;
216 |
217 | NSUInteger indexofLastCell = [_tableView numberOfRowsInSection:0] - 1;
218 |
219 | NSIndexPath *indexPath = [NSIndexPath indexPathForRow:indexofLastCell inSection:0];
220 | CGFloat heightOfContent = [_tableView rectForRowAtIndexPath:indexPath].origin.y + _collapsedHeight;
221 |
222 | CGPoint newContentOffset = CGPointZero;
223 |
224 | if (visibleTableHeight > heightOfContent) {
225 | newContentOffset = CGPointMake(_tableView.contentOffset.x, 0.f - _insetTableView.top);
226 | }
227 | else {
228 | CGFloat maxContentOffset = heightOfContent - visibleTableHeight;
229 | CGFloat percentOfMaxOffset = 0.0f;
230 |
231 | if ((CGFloat)(indexofLastCell - 2) != 0) {
232 | percentOfMaxOffset = MIN(1.f, indexSelected / (CGFloat)(indexofLastCell - 2));
233 | }
234 |
235 | newContentOffset = CGPointMake(_tableView.contentOffset.x, maxContentOffset * percentOfMaxOffset - _insetTableView.top);
236 | }
237 |
238 | void (^blockScrollToBorder)(void) = ^(void)
239 | {
240 | _tableView.contentOffset = newContentOffset;
241 |
242 | CGPoint offset = _tableView.contentOffset;
243 | _tableView.contentInset = _insetTableView;
244 | _tableView.contentOffset = offset;
245 | };
246 |
247 | if (animated) {
248 | [UIView animateWithDuration:0.3f animations:blockScrollToBorder];
249 | }
250 | else {
251 | blockScrollToBorder();
252 | }
253 | }
254 |
255 | -(void)setScrollEnabledExpand:(BOOL)scrollEnabledExpand
256 | {
257 | _scrollEnabledExpand = scrollEnabledExpand;
258 |
259 | if (_isExpand) {
260 | _tableView.scrollEnabled = scrollEnabledExpand;
261 | }
262 | }
263 |
264 | -(void)setScrollEnabledCollapse:(BOOL)scrollEnabledCollapse
265 | {
266 | _scrollEnabledCollapse = scrollEnabledCollapse;
267 |
268 | if (!_isExpand) {
269 | _tableView.scrollEnabled = scrollEnabledCollapse;
270 | }
271 | }
272 |
273 | -(void)setStatus:(ANWExpandScrollViewStatus)status
274 | {
275 | if (status == _status) {
276 | return;
277 | }
278 |
279 | if ([_delegate respondsToSelector:@selector(expandScrollView:changedStatus:previousStatus:)]) {
280 | [_delegate expandScrollView:self changedStatus:status previousStatus:_status];
281 | }
282 |
283 | _status = status;
284 | }
285 |
286 | - (void)expandAtIndex:(NSInteger)index animated:(BOOL)animated
287 | {
288 | _currentPageIndex = index;
289 |
290 | self.height = _expandedHeight;
291 |
292 | _isExpand = YES;
293 |
294 | [self updateCellsHeightsAnimated:animated];
295 |
296 | [self scrollToTopCellAtIndex:index animated:animated];
297 |
298 | _tableView.scrollEnabled = self.scrollEnabledExpand;
299 |
300 | self.status = ANWExpandScrollViewStatusExpand;
301 |
302 | _tableView.separatorColor = [UIColor clearColor];
303 | }
304 |
305 | - (void)collapseWithAnimated:(BOOL)animated
306 | {
307 | _currentPageIndex = NSNotFound;
308 |
309 | _tableView.contentInset = UIEdgeInsetsMake(_tableView.frame.size.height, 0.f, _tableView.frame.size.height, 0.f);
310 |
311 | self.height = _collapsedHeight;
312 |
313 | self.isExpand = NO;
314 |
315 | [self updateCellsHeightsAnimated:animated];
316 |
317 | [self scrollToContentBoundsCellAtIndex:_indexOfPinchingElement animated:animated];
318 |
319 | _tableView.scrollEnabled = self.scrollEnabledCollapse;
320 |
321 | self.status = ANWExpandScrollViewStatusCollapse;
322 |
323 | _tableView.separatorColor = [UIColor whiteColor];
324 | }
325 |
326 | - (void)reloadData
327 | {
328 | _items = [NSMutableArray array];
329 | for (NSUInteger i = 0; i < [_dataSource numberOfItemsInScrollView:self]; i++) {
330 | [_items addObject:@""];
331 | }
332 |
333 | _expandedHeight = [UIScreen mainScreen].bounds.size.height;
334 | _collapsedHeight = COLLAPSE_DEFAULTH_HEIGHT;
335 |
336 | if ([_delegate respondsToSelector:@selector(collapseHeightInScrollView:index:)]) {
337 | _collapsedHeight = [_delegate collapseHeightInScrollView:self index:_indexOfPinchingElement];
338 | }
339 |
340 | if ([_delegate respondsToSelector:@selector(expandHeightInScrollView:index:)]) {
341 | _expandedHeight = [_delegate expandHeightInScrollView:self index:_indexOfPinchingElement];
342 | }
343 | self.height = _isExpand ? _expandedHeight : _collapsedHeight;
344 |
345 | [_tableView reloadData];
346 | }
347 |
348 | -(UIView*)itemWithIndex:(NSUInteger)index
349 | {
350 | UIView *view = nil;
351 |
352 | if (_items.count > index) {
353 |
354 | view = _items[index];
355 | if (![view isKindOfClass:[UIView class]]) {
356 | view = [_dataSource expandScrollView:self viewForItemAtIndex:index];
357 | [_items replaceObjectAtIndex:index withObject:view];
358 | }
359 |
360 | if (view) {
361 |
362 | CGRect frame = view.frame;
363 | frame.size.height = _height;
364 | frame.size.width = self.frame.size.width;
365 | [view setFrame:frame];
366 | }
367 | }
368 | return view;
369 | }
370 |
371 | -(UIView*)visibleItemAtIndex:(NSUInteger)index
372 | {
373 | UIView *view = nil;
374 |
375 | if (_items.count > index) {
376 |
377 | view = _items[index];
378 | if (![view isKindOfClass:[UIView class]]) {
379 | view = nil;
380 | }
381 |
382 | }
383 |
384 | return view;
385 | }
386 |
387 | -(NSArray *)visibleItemIndexs
388 | {
389 | NSMutableArray *indexes = [NSMutableArray array];
390 |
391 | for (NSIndexPath *indexPath in _tableView.indexPathsForVisibleRows) {
392 | [indexes addObject:@(indexPath.row)];
393 | }
394 |
395 | return indexes;
396 | }
397 |
398 | #pragma mark - UITableView Delegates
399 |
400 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
401 | {
402 | if ([_delegate respondsToSelector:@selector(expandScrollView:didSelectItemAtIndex:)]) {
403 | [_delegate expandScrollView:self didSelectItemAtIndex:indexPath.row];
404 | }
405 |
406 | [tableView deselectRowAtIndexPath:indexPath animated:YES];
407 | }
408 |
409 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
410 | {
411 | return _items.count;
412 | }
413 |
414 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
415 | {
416 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"expandScrollViewCell"];
417 | if (!cell) {
418 | cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"expandScrollViewCell"];
419 | cell.backgroundColor = [UIColor clearColor];
420 | cell.contentView.backgroundColor = [UIColor clearColor];
421 | cell.layer.masksToBounds = YES;
422 | }
423 |
424 | UIView *view = [self itemWithIndex:indexPath.row];
425 |
426 | for (UIView *subview in cell.contentView.subviews) {
427 | [subview removeFromSuperview];
428 | }
429 |
430 | [view setFrame:view.bounds];
431 |
432 | [cell.contentView setFrame:view.bounds];
433 |
434 | [cell setFrame:view.bounds];
435 |
436 | [cell.contentView addSubview:view];
437 |
438 | return cell;
439 | }
440 |
441 | -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
442 | {
443 | return _height;
444 | }
445 |
446 | -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
447 | {
448 | UIView *view = [[UIView alloc]initWithFrame:CGRectZero];
449 | return view;
450 | }
451 |
452 | -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
453 | {
454 | return 1.0f;
455 | }
456 |
457 | -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
458 | {
459 | // Remove seperator inset
460 | if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
461 | [cell setSeparatorInset:UIEdgeInsetsZero];
462 | }
463 |
464 | // Prevent the cell from inheriting the Table View's margin settings
465 | if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
466 | [cell setPreservesSuperviewLayoutMargins:NO];
467 | }
468 |
469 | // Explictly set your cell's layout margins
470 | if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
471 | [cell setLayoutMargins:UIEdgeInsetsZero];
472 | }
473 | }
474 |
475 | #pragma mark - UIScrollView Delegates
476 |
477 |
478 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView
479 | {
480 |
481 | }
482 |
483 | @end
484 |
--------------------------------------------------------------------------------
/ExpandScrollViewDemo/ExpandScrollViewDemo/ExpandScrollView/ANWExpandScrollView.m:
--------------------------------------------------------------------------------
1 | //
2 | // ANWExpandScrollView.m
3 | // OmsaTech
4 | //
5 | // Created by Anil Oruc on 7/23/15.
6 | // Copyright (c) 2015 OmsaTech. All rights reserved.
7 | //
8 |
9 | #import "ANWExpandScrollView.h"
10 |
11 | #define COLLAPSE_DEFAULTH_HEIGHT 44.0f
12 |
13 | @interface ANWExpandScrollView ()
14 | {
15 | UIPinchGestureRecognizer *pgr;
16 |
17 | NSInteger _indexOfPinchingElement;
18 | CGFloat _initialHeightOfPinchingElement;
19 | CGPoint _offsetTableViewBeforePinching;
20 | UIEdgeInsets _insetTableView;
21 | CGFloat _expandedHeight;
22 | CGFloat _collapsedHeight;
23 |
24 | NSMutableArray *_items;
25 | }
26 |
27 | @property (weak, nonatomic) IBOutlet UITableView *tableView;
28 |
29 | @property (nonatomic, assign) BOOL isExpand;
30 |
31 | @property (nonatomic, assign) NSUInteger currentPageIndex;
32 | @property (nonatomic, assign) CGFloat height;
33 |
34 | @end
35 |
36 | @implementation ANWExpandScrollView
37 |
38 | + (instancetype)init
39 | {
40 | ANWExpandScrollView *view = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil].firstObject;
41 | if (view) {
42 |
43 | [view loadView];
44 | }
45 | return view;
46 | }
47 |
48 | + (instancetype)initWithFrame:(CGRect)frame
49 | {
50 | ANWExpandScrollView *view = [self init];
51 | if (view)
52 | {
53 | [view setFrame:frame];
54 | }
55 | return view;
56 | }
57 |
58 | -(void)setFrame:(CGRect)frame
59 | {
60 | [super setFrame:frame];
61 |
62 | [self setNeedsLayout];
63 | [self layoutIfNeeded];
64 |
65 | }
66 |
67 | -(void)loadView
68 | {
69 | _isExpand = NO;
70 | _scrollEnabledCollapse = YES;
71 | _scrollEnabledExpand = NO;
72 | _currentPageIndex = NSNotFound;
73 | _status = ANWExpandScrollViewStatusCollapse;
74 |
75 | [self addPinchGestureRecognizer];
76 | }
77 |
78 | -(void)addPinchGestureRecognizer
79 | {
80 | [pgr removeTarget:self action:@selector(handlePinch:)];
81 | pgr = nil;
82 | pgr = [[UIPinchGestureRecognizer alloc]
83 | initWithTarget:self action:@selector(handlePinch:)];
84 | pgr.delegate = self;
85 |
86 | [self addGestureRecognizer:pgr];
87 | }
88 |
89 |
90 | - (void)handlePinch:(UIPinchGestureRecognizer *)pinchGestureRecognizer
91 | {
92 | if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan) {
93 | [self onPinchBegan:pinchGestureRecognizer];
94 | }
95 | else if (pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {
96 | [self onPinchChanged:pinchGestureRecognizer];
97 | }
98 | else if ((pinchGestureRecognizer.state == UIGestureRecognizerStateCancelled) || (pinchGestureRecognizer.state == UIGestureRecognizerStateEnded)) {
99 | [self onPinchEnded:pinchGestureRecognizer];
100 | }
101 | }
102 |
103 | - (void)onPinchBegan:(UIPinchGestureRecognizer*)pinchRecognizer
104 | {
105 | _indexOfPinchingElement = NSNotFound;
106 |
107 | CGPoint pinchLocation = [pinchRecognizer locationInView:_tableView];
108 | NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:pinchLocation];
109 |
110 | if (indexPath != nil) {
111 |
112 | self.status = ANWExpandScrollViewStatusPinching;
113 |
114 | _indexOfPinchingElement = indexPath.row;
115 |
116 | _initialHeightOfPinchingElement = _height;
117 | _offsetTableViewBeforePinching = _tableView.contentOffset;
118 |
119 | _tableView.contentInset = UIEdgeInsetsMake(_tableView.frame.size.height, 0.f, _tableView.frame.size.height, 0.f);
120 | }
121 | }
122 |
123 | - (void)onPinchChanged:(UIPinchGestureRecognizer*)pinchRecognizer
124 | {
125 | if (_indexOfPinchingElement == NSNotFound) {
126 | return;
127 | }
128 |
129 | CGFloat newHeight = (_initialHeightOfPinchingElement * pinchRecognizer.scale);
130 |
131 | self.height = newHeight;
132 |
133 | [self updateCellsHeightsAnimated:NO];
134 |
135 | CGFloat diffHeight = newHeight - _initialHeightOfPinchingElement;
136 | CGFloat yOffsetTableView = _offsetTableViewBeforePinching.y + (_indexOfPinchingElement * diffHeight) + (diffHeight / 2.f);
137 | _tableView.contentOffset = CGPointMake(_offsetTableViewBeforePinching.x, yOffsetTableView);
138 |
139 | }
140 |
141 | - (void)onPinchEnded:(UIPinchGestureRecognizer*)pinchRecognizer
142 | {
143 | if (_indexOfPinchingElement == NSNotFound) {
144 | return;
145 | }
146 |
147 | CGPoint offset = _tableView.contentOffset;
148 | _tableView.contentInset = _insetTableView;
149 | _tableView.contentOffset = offset;
150 |
151 | BOOL open = NO;
152 | if (_initialHeightOfPinchingElement > _height) { //open
153 | open = _height > _expandedHeight * 0.8f;
154 | }
155 | else { //close
156 | open = _height > _expandedHeight * 0.2f;
157 | }
158 |
159 | if (open) {
160 | [self expandAtIndex:_indexOfPinchingElement animated:NO];
161 |
162 | }
163 | else {
164 | [self collapseWithAnimated:NO];
165 | }
166 | }
167 |
168 | -(void)setHeight:(CGFloat)height
169 | {
170 | _height = MIN(_expandedHeight, MAX(height, _collapsedHeight));
171 |
172 | [self allCellsHeightChanged];
173 | }
174 |
175 | -(void)allCellsHeightChanged
176 | {
177 | for (UIView *item in _items) {
178 | if ([item isKindOfClass:[UIView class]]) {
179 |
180 | CGRect frame = item.frame;
181 | frame.size.height = _height;
182 | frame.size.width = self.frame.size.width;
183 | [item setFrame:frame];
184 | }
185 | }
186 | }
187 |
188 | - (void)updateCellsHeightsAnimated:(BOOL)animated
189 | {
190 | BOOL animationsEnabled = [UIView areAnimationsEnabled];
191 | [UIView setAnimationsEnabled:animated];
192 | [_tableView beginUpdates];
193 | [_tableView reloadData];
194 | [_tableView endUpdates];
195 | [UIView setAnimationsEnabled:animationsEnabled];
196 | }
197 |
198 | - (void)scrollToTopCellAtIndex:(NSUInteger)index animated:(BOOL)animated
199 | {
200 | @try {
201 |
202 | NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
203 | [_tableView scrollToRowAtIndexPath:([_tableView numberOfRowsInSection:0] > index ? indexPath : [NSIndexPath indexPathForRow:[_tableView numberOfRowsInSection:0]-1 inSection:0]) atScrollPosition:UITableViewScrollPositionTop animated:animated];
204 | }
205 | @catch (NSException *exception) {
206 | [_tableView reloadData];
207 | }
208 | @finally {
209 |
210 | }
211 | }
212 |
213 | - (void)scrollToContentBoundsCellAtIndex:(NSInteger)indexSelected animated:(BOOL)animated
214 | {
215 | CGFloat visibleTableHeight = _tableView.frame.size.height - _insetTableView.top - _insetTableView.bottom;
216 |
217 | NSUInteger indexofLastCell = [_tableView numberOfRowsInSection:0] - 1;
218 |
219 | NSIndexPath *indexPath = [NSIndexPath indexPathForRow:indexofLastCell inSection:0];
220 | CGFloat heightOfContent = [_tableView rectForRowAtIndexPath:indexPath].origin.y + _collapsedHeight;
221 |
222 | CGPoint newContentOffset = CGPointZero;
223 |
224 | if (visibleTableHeight > heightOfContent) {
225 | newContentOffset = CGPointMake(_tableView.contentOffset.x, 0.f - _insetTableView.top);
226 | }
227 | else {
228 | CGFloat maxContentOffset = heightOfContent - visibleTableHeight;
229 | CGFloat percentOfMaxOffset = 0.0f;
230 |
231 | if ((CGFloat)(indexofLastCell - 2) != 0) {
232 | percentOfMaxOffset = MIN(1.f, indexSelected / (CGFloat)(indexofLastCell - 2));
233 | }
234 |
235 | newContentOffset = CGPointMake(_tableView.contentOffset.x, maxContentOffset * percentOfMaxOffset - _insetTableView.top);
236 | }
237 |
238 | void (^blockScrollToBorder)(void) = ^(void)
239 | {
240 | _tableView.contentOffset = newContentOffset;
241 |
242 | CGPoint offset = _tableView.contentOffset;
243 | _tableView.contentInset = _insetTableView;
244 | _tableView.contentOffset = offset;
245 | };
246 |
247 | if (animated) {
248 | [UIView animateWithDuration:0.3f animations:blockScrollToBorder];
249 | }
250 | else {
251 | blockScrollToBorder();
252 | }
253 | }
254 |
255 | -(void)setScrollEnabledExpand:(BOOL)scrollEnabledExpand
256 | {
257 | _scrollEnabledExpand = scrollEnabledExpand;
258 |
259 | if (_isExpand) {
260 | _tableView.scrollEnabled = scrollEnabledExpand;
261 | }
262 | }
263 |
264 | -(void)setScrollEnabledCollapse:(BOOL)scrollEnabledCollapse
265 | {
266 | _scrollEnabledCollapse = scrollEnabledCollapse;
267 |
268 | if (!_isExpand) {
269 | _tableView.scrollEnabled = scrollEnabledCollapse;
270 | }
271 | }
272 |
273 | -(void)setStatus:(ANWExpandScrollViewStatus)status
274 | {
275 | if (status == _status) {
276 | return;
277 | }
278 |
279 | if ([_delegate respondsToSelector:@selector(expandScrollView:changedStatus:previousStatus:)]) {
280 | [_delegate expandScrollView:self changedStatus:status previousStatus:_status];
281 | }
282 |
283 | _status = status;
284 | }
285 |
286 | - (void)expandAtIndex:(NSInteger)index animated:(BOOL)animated
287 | {
288 | _currentPageIndex = index;
289 |
290 | self.height = _expandedHeight;
291 |
292 | _isExpand = YES;
293 |
294 | [self updateCellsHeightsAnimated:animated];
295 |
296 | [self scrollToTopCellAtIndex:index animated:animated];
297 |
298 | _tableView.scrollEnabled = self.scrollEnabledExpand;
299 |
300 | self.status = ANWExpandScrollViewStatusExpand;
301 |
302 | _tableView.separatorColor = [UIColor clearColor];
303 | }
304 |
305 | - (void)collapseWithAnimated:(BOOL)animated
306 | {
307 | _currentPageIndex = NSNotFound;
308 |
309 | _tableView.contentInset = UIEdgeInsetsMake(_tableView.frame.size.height, 0.f, _tableView.frame.size.height, 0.f);
310 |
311 | self.height = _collapsedHeight;
312 |
313 | self.isExpand = NO;
314 |
315 | [self updateCellsHeightsAnimated:animated];
316 |
317 | [self scrollToContentBoundsCellAtIndex:_indexOfPinchingElement animated:animated];
318 |
319 | _tableView.scrollEnabled = self.scrollEnabledCollapse;
320 |
321 | self.status = ANWExpandScrollViewStatusCollapse;
322 |
323 | _tableView.separatorColor = [UIColor whiteColor];
324 | }
325 |
326 | - (void)reloadData
327 | {
328 | _items = [NSMutableArray array];
329 | for (NSUInteger i = 0; i < [_dataSource numberOfItemsInScrollView:self]; i++) {
330 | [_items addObject:@""];
331 | }
332 |
333 | _expandedHeight = [UIScreen mainScreen].bounds.size.height;
334 | _collapsedHeight = COLLAPSE_DEFAULTH_HEIGHT;
335 |
336 | if ([_delegate respondsToSelector:@selector(collapseHeightInScrollView:index:)]) {
337 | _collapsedHeight = [_delegate collapseHeightInScrollView:self index:_indexOfPinchingElement];
338 | }
339 |
340 | if ([_delegate respondsToSelector:@selector(expandHeightInScrollView:index:)]) {
341 | _expandedHeight = [_delegate expandHeightInScrollView:self index:_indexOfPinchingElement];
342 | }
343 | self.height = _isExpand ? _expandedHeight : _collapsedHeight;
344 |
345 | [_tableView reloadData];
346 | }
347 |
348 | -(UIView*)itemWithIndex:(NSUInteger)index
349 | {
350 | UIView *view = nil;
351 |
352 | if (_items.count > index) {
353 |
354 | view = _items[index];
355 | if (![view isKindOfClass:[UIView class]]) {
356 | view = [_dataSource expandScrollView:self viewForItemAtIndex:index];
357 | [_items replaceObjectAtIndex:index withObject:view];
358 | }
359 |
360 | if (view) {
361 |
362 | CGRect frame = view.frame;
363 | frame.size.height = _height;
364 | frame.size.width = self.frame.size.width;
365 | [view setFrame:frame];
366 | }
367 | }
368 | return view;
369 | }
370 |
371 | -(UIView*)visibleItemAtIndex:(NSUInteger)index
372 | {
373 | UIView *view = nil;
374 |
375 | if (_items.count > index) {
376 |
377 | view = _items[index];
378 | if (![view isKindOfClass:[UIView class]]) {
379 | view = nil;
380 | }
381 |
382 | }
383 |
384 | return view;
385 | }
386 |
387 | -(NSArray *)visibleItemIndexs
388 | {
389 | NSMutableArray *indexes = [NSMutableArray array];
390 |
391 | for (NSIndexPath *indexPath in _tableView.indexPathsForVisibleRows) {
392 | [indexes addObject:@(indexPath.row)];
393 | }
394 |
395 | return indexes;
396 | }
397 |
398 | #pragma mark - UITableView Delegates
399 |
400 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
401 | {
402 | if ([_delegate respondsToSelector:@selector(expandScrollView:didSelectItemAtIndex:)]) {
403 | [_delegate expandScrollView:self didSelectItemAtIndex:indexPath.row];
404 | }
405 |
406 | [tableView deselectRowAtIndexPath:indexPath animated:YES];
407 | }
408 |
409 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
410 | {
411 | return _items.count;
412 | }
413 |
414 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
415 | {
416 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"expandScrollViewCell"];
417 | if (!cell) {
418 | cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"expandScrollViewCell"];
419 | cell.backgroundColor = [UIColor clearColor];
420 | cell.contentView.backgroundColor = [UIColor clearColor];
421 | cell.layer.masksToBounds = YES;
422 | }
423 |
424 | UIView *view = [self itemWithIndex:indexPath.row];
425 |
426 | for (UIView *subview in cell.contentView.subviews) {
427 | [subview removeFromSuperview];
428 | }
429 |
430 | [view setFrame:view.bounds];
431 |
432 | [cell.contentView setFrame:view.bounds];
433 |
434 | [cell setFrame:view.bounds];
435 |
436 | [cell.contentView addSubview:view];
437 |
438 | return cell;
439 | }
440 |
441 | -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
442 | {
443 | return _height;
444 | }
445 |
446 | -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
447 | {
448 | UIView *view = [[UIView alloc]initWithFrame:CGRectZero];
449 | return view;
450 | }
451 |
452 | -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
453 | {
454 | return 1.0f;
455 | }
456 |
457 | -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
458 | {
459 | // Remove seperator inset
460 | if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
461 | [cell setSeparatorInset:UIEdgeInsetsZero];
462 | }
463 |
464 | // Prevent the cell from inheriting the Table View's margin settings
465 | if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
466 | [cell setPreservesSuperviewLayoutMargins:NO];
467 | }
468 |
469 | // Explictly set your cell's layout margins
470 | if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
471 | [cell setLayoutMargins:UIEdgeInsetsZero];
472 | }
473 | }
474 |
475 | #pragma mark - UIScrollView Delegates
476 |
477 |
478 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView
479 | {
480 |
481 | }
482 |
483 | @end
484 |
--------------------------------------------------------------------------------