UIKitHelper 0.0.3

UIKitHelper 0.0.3

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Unclaimed.



  • By
  • Zhang Zonghui

UIKitHellper is a collection of UIKit classes that makes some common view behaviors easily to implement, like tap background to hide keyboard, infinite scroll view, etc.


1. ISPageScrollView

Description

ISPageScrollView is a UIScrollView subclass optimised for huge number of pages display. It uses lazy-loading mechanism to maintain only the previous few pages and the next few pages in order to minimize the memory usage.

Properties:

id<ISPageScrollViewDataSource> dataSource: Like UITableViewDataSource, it asks its dataSource object for views displayed in each page.

NSInteger numberOfReusablePages: number of pages maintanined in memory. This number should be an odd number (e.g: 5 = current displayed page + 2 pages in front + 2 pages after)

NSInteger numberOfPages: number of total pages

NSMutableDictionary readonly scrollViewAvailablePages: this is the dictionary that stores the views of the pages in memory. The keys for the dictionary are NSNumbers for page index. The values for each key is an UIView object.

Usage

It can be created in xcode like UIScollView or can be created programatically.

ISPageScrollView *pageScrollView = [[ISPageScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
pageScrollView.dataSource = self;
pageScrollView.numberOfPages = 10;
pageScrollView.numberOfReusableViews = 5;

[pageScrollView displayPage:0];

You also need to implement the datasource methods like UITableView in order for the page scroll view to know what to display

@interface ViewController () <ISPageScrollViewDataSource>

@end

@implementation ViewController
…

#pragma mark - ISPageScrollViewDataSource

- (UIView *)viewForScrollView:(UIScrollView *)scrollView Page:(NSInteger)pageIndex
{
    UIView *pageView = [[UIView alloc] initWithFrame:scrollView.frame];
    pageView.backgroundColor = [UIColor colorWithRed:pageIndex * 10 / 255.0 green:pageIndex * 10 / 255.0 blue:pageIndex * 10 / 255.0 alpha:1.0];
    return pageView;
}

…
@end

2. AutoHideKeyboardViewController

Description

AutoHideKeyboardViewController is a subclass of UIViewController which enables the tap background to hide keyboard behavior.

Usage

There are only 2 steps to make your viewcontroller hide keyboard on background tapped.

Step 1: Make your viewcontroller a subclass of AutoHideKeyboardViewController instead of UIViewController

#import "AutoHideKeyboardViewController.h"

@interface ViewController : AutoHideKeyboardViewController

Step 2: If you have any UITextView or UITextField in your page, set their delegate to your viewcontroller.

That's it!


3. AutoHideKeyboardTableViewController

The usage and the behaviour is the same as AutoHideKeyboardViewController. This is for UITableView to implement 'tap background to dismiss keyboard' behavior.

License


UIKitHelper is available under the MIT license. See the LICENSE file for more info.