Code Monkey home page Code Monkey logo

solocomponents-ios's Introduction

Self-Contained Components for iOS

Two-file (.h / .m) useful components and utility classes that are dead-easy to drop into your iOS projects.

License: MIT (free for any use, no attribution required).

Follow us on twitter: @SoloComponents.

Note: I want to collect as many open-source components as possible, not just publish my own ones. If you have a useful iOS class that does not depend on anything, feel free to fork, add and send me a pull request!

ATPagingView

ATPagingView is a wrapper around UIScrollView in (horizontal) paging mode, with an API similar to UITableView.

Status: production-ready, used by at least one App Store app.

You provide the page views by implementing two delegate methods:

- (NSInteger)numberOfPagesInPagingView:(ATPagingView *)pagingView {
    return 10;
}

- (UIView *)viewForPageInPagingView:(ATPagingView *)pagingView atIndex:(NSInteger)index {
    UIView *view = [pagingView dequeueReusablePage];
    if (view == nil) {
        view = [[[DemoPageView alloc] init] autorelease];
    }
    return view;
}

You are also notified when the user navigates between pages:

- (void)currentPageDidChangeInPagingView:(ATPagingView *)pagingView {
    self.navigationItem.title = [NSString stringWithFormat:@"%d of %d", pagingView.currentPageIndex+1, pagingView.pageCount];
}

You can use ATPagingView directly or derive your view controller from ATPagingViewController.

ATPagingViewController is similar to UITableViewController and:

  • defines loadView to create ATPagingView automatically,
  • sets itself as a delegate of ATPagingView,
  • calls reloadData in viewWillAppear: if the paging view is empty,
  • additionally it forwards orientation events to the paging view (see below).

If you want to use ATPagingView without ATPagingViewController, you need to:

  • provide your delegate object using the delegate property,

  • call reloadData to populate the view,

  • if you want to support rotation, you need to invoke willAnimateRotation and didRotate methods from your view controller:

    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [self.pagingView willAnimateRotation];
    }
    
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
        [self.pagingView didRotate];
    }
    

ATArrayView

A container that arranges its items in rows and columns similar to the thumbnails screen in Photos.app, the API is modeled after UITableView.

Status: beta.

Enjoy the familiar delegate methods:

- (NSInteger)numberOfItemsInArrayView:(ATArrayView *)arrayView {
    return 97;
}

- (UIView *)viewForItemInArrayView:(ATArrayView *)arrayView atIndex:(NSInteger)index {
    DemoItemView *itemView = (DemoItemView *) [arrayView dequeueReusableItem];
    if (itemView == nil) {
        itemView = [[[DemoItemView alloc] init] autorelease];
    }
    return itemView;
}

There's ATArrayViewController which further reduces the amount of boilerplate code you have to write. Similar to UITableViewController, it:

  • overrides loadView to create ATArrayView automatically,
  • sets itself as a delegate of the array view,
  • calls reloadData in viewWillAppear: if the array view is empty.

ATByteImage

Allows to easily use an image (CGImageRef) backed by a malloc'ed chunk of memory. This means you can read or manipulate image bytes directly.

Status: ready for production use.

Using ATByteImage:

ATByteImage *blurred = [[ATByteImage alloc] initWithSize:blurredSize];
[blurred clear];

ATByteImageContext *blurredContext = [blurred newContext];
CGContextSetBlendMode(blurredContext.CGContext, kCGBlendModeNormal);
... draw using blurredContext.CGContext ...
[blurredContext release];

  UIImage *myOverlay = [blurred extractImage];

Here's another example. The following function is useful in background image loading code:

// Returns an uncompressed (decoded) UIImage, optimized for drawing speed.
//
// This is a middle ground between [UIImage imageNamed:] and a plain
// [UIImage imageWithContentsOfFile:], as follows:
//
// * [UIImage imageWithContentsOfFile:] loads image data from disk and
//   decodes it each time you display the image.
//
//   If you are using CATiledLayer to display a large image (and you should,
//   since UIImageView is not recommended for images bigger than ~1024x1024),
//   the whole JPEG will decoded for EACH tile you display.
//
// * [UIImage imageNamed:@"xxx"] only ever decodes the image once, just as you
//   wanted. However it also caches the image and seems to sometimes (always?)
//   not release the data even after you release your UIImage.
//
//   An app that loads several large images via 'imageNamed' will thus crash
//   quite soon with unfamous "error 0".
//
//   Another undesired quality of 'imageNamed' is that the image is loaded and
//   decoded when it is displayed for the first time, which means you can't
//   really do the decoding in a background thread.
//
// * DecompressUIImage([UIImage imageWithContentsOfFile:@"xx.jpg"]) is the
//   sweet spot between the two โ€” it returns a fully decoded image which can
//   be displayed quickly, and memory management is entirely up to you.
//
UIImage *DecompressUIImage(UIImage *image) {
    ATByteImage *byteImage = [[[ATByteImage alloc] initWithImage:image] autorelease];
    return [byteImage extractImage];
}

solocomponents-ios's People

Contributors

andreyvit avatar jonsterling avatar robpearson67 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

solocomponents-ios's Issues

dealloc doesn't get called in pageView of ATPagingView

Hi, I love using ATPagingView!

My current ARC-enabled iPad project uses ATPagingView to present a set of custom UIView, which displays
image (with UIImageView),
html (with UIWebView)
video (with MPMoviePlayerController.view).

Now I'm getting memory warning and crashes, which I believe is caused by not releasing resource used in unseen pageView. I wrote the dealloc method, but it didn't get called.

Your sample project doesn't show much about resource allocating/deallocing. so I came here and raised this sort of question.

Many thanks!

Should DemoPageView dealloc be firing?

Hi Andrey,

Thanks for sharing this code. I loaded the ATPagingViewDemo project into the iPad 5.0 simulator and wanted to see when the DemoPageView object got dealloc'ed. I put a breakpoint on the dealloc method but I'm not seeing it get fired as you scroll. Forgive me if I'm getting confused here, but should the pages be getting dealloc'ed once it is not in view or either side of selected page?

Want to access all iphone file

hi.....
i want to copy my iphone files to computer without jail-breaking my iphone. i had tried iphonebrowsercode but only able to access few files, some file are remaining how can i got access on those remaining files(sms.db,call_history.db ,etc) ....

Bug with - (UIView *)dequeueReusablePage

Please change from:

  • (UIView *)dequeueReusablePage {
    UIView *result = [_recycledPages anyObject];
    if (result) {
    [_recycledPages removeObject:[[result retain] autorelease]];

    }
    return result;
    }

to:

  • (UIView *)dequeueReusablePage {
    UIView *result = [_recycledPages anyObject];
    if (result) {
    [_recycledPages removeObject:[[result retain] autorelease]];
    return nil;
    }
    return result;
    }

otherwise the removeObject has no effect.

use ATPagingView without ATPagingViewController

Hello,

Can you please give an example, how can I do this

If you want to use ATPagingView without ATPagingViewController, you need to:

provide your delegate object using the delegate property,
call reloadData to populate the view,

Animation on scrollview

It would be nice to allow the developer to set a desired animation style instead of scrolling when changing pages.

ATPagingView setGapBetweenPages found bug and fix, just add this code.

  1. When ATPagingView is created you applying scroll view frame like: "_scrollView.frame = [self frameForScrollView];"
  2. When you getting frame for the page using scrollView frame sizes.
    But if set gap (ofcource after creation ATPagingView) you don't change scrollView frame.
    So add "_scrollView.frame = [self frameForScrollView];" to method named: "- (void)setGapBetweenPages:(CGFloat)value"

layoutSubviews not always called in ATPagingView custom page views

Hello. I'd like to use just like I use a TableViewCOntroller with custom cells, that is: in viewForPage... I set a data property for my custom view:

  • (UIView *)viewForPageInPagingView:(ATPagingView *)pagingView atIndex:(NSInteger)index
    {
    GalleryPageView *view = (GalleryPageView *)[pagingView dequeueReusablePage];
    if (view == nil) {
    view = [[[GalleryPageView alloc] init] autorelease];
    }

    FeedItem *feedItem = [dataRoot objectAtIndex:index];
    view.feedItem = feedItem;

and then I perform some modifications to custom subviews of view by overwriting its layoutSubviews method.
But that method seems to be called only for the first couple of cells. so I can't do that. Am I missing something in TableView programming model? Where do you suggest I put my custom-subviews-code?

By the way: Thank you, good job.

How to just load and remain pages but not to preload them all?

First, great component, nice work! Currently, I'm trying to use it as image gallery browser. I'm returning an ImageView in viewForPageInPagingView method in delegate. However, the default behavior is, if I'm adding more than three pages (images) then pages begin to duplicate because there's a reuse mechanism (default pagesToPreload is 1). I can't preload all the images (for example set pagesToPreload = 30), because it will take too much time. I just need to preload 1 page, then load pages as user scrolls and to remain them on pages (do not remove from superview). Is it possible to achieve?

Sorting of Views by adding left & top coloumn

I am looking to make the calendar similar to iOS4 while in Landscape mode using the same class.So, How can I add the Top & left Column & allowing user to rag & Drop / swap the UIView within the same Scrollview. Will it be possible to have the same ?

Thanks,

Double pages in landscape

It would be nice to have an option to present two pages in landscape mode.
In case you would like to introduce this, please take under consideration the single/double start page problem. This means, in landscape the first screen can show one or two pages, determined by a property. Also it can be useful to determine the location of a page if it is a single page.
If you need more detailed description you can message me.

ATPagingView not always calling viewForPageInPagingView: with correct index

Not always but sometimes viewForPageInPagingView: is getting called with the wrong index. For instance it'll have 10 for the index when currentPageIndex in pagingViewDidEndMoving: reports 8 and then I flip back one and it's 3 and 7. Any help on this would be VERY welcome! Thanks! If you need debug logs just let me know what you need!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.