SBIconListView

From iPhone Development Wiki
Revision as of 13:13, 5 September 2013 by Caughtinflux (talk | contribs) (Created page with "{{occlass|library=SpringBoard.app}} '''SBIconListView''' is a UIView subclass that contains list of icons (SBIconView objects). Each page on the home screen is ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


SBIconListView is a UIView subclass that contains list of icons (SBIconView objects). Each page on the home screen is a different instance of SBIconListView

Notable Subclasses

General

It is backed by a SBIconModel for the icons, and a SBIconViewMap, which handles the recycling of icon views, accessory updates, and some basic folder handling (nodes). SBIconListView handles the rotation of lists, animations for app launching, transforms, icon additions, layouts, etc. All the views of this class on the home screen are managed by the SBIconController singleton. Since it is just a subclass of UIView, it fits into the "View" of the "Model-View-Controller" paradigm. Thus, any changes made to the visible icons by this class are not saved. For modifying / adding icons, look at SBIconModel.

Edit mode & icon moving

Icon moving in edit/wiggle mode is not, contrary to expectations, related at all to where icons are located onscreen. If you have a 4x4 home screen but you play with the originForIconAtX:Y: values returned for each of these icons, you will notice that moving icons around will be exactly the same as it was before you changed their origins. Two methods, columnAtPoint: and rowAtPoint: estimate which column and row you are in according to the point passed in. Anyone wanting to make icon moving more natural for a modified layout would have to hook these methods accordingly.

Icon Coordinates

All the icons in this view are backed by an index -- a NSUInteger. As expected, the indexes start from 0 for the icon at the top-left, to +[SBIconListView maxIcons] - 1. You can find icons' locations in the view by using -[SBIconListView originForIcon:], -originForIconAtIndex, or -originForIconAtX:Y:. Do note, the last method does not always return a point within the view's bounds, but rather simply calculates it using simple math.

There is also -iconAtPoint:, which gives the icon for a CGPoint that is inside the list view's bounds.

Modifying Icon Locations

Hooking into the methods mentioned above is the best way to modify the position of an icon on the home screen, rather than explicitly modifying its frame with a bunch of hacks to detect changes.

Note

If you ever mess up the contained icon views' frames too much, the following is magick.

   [listView setIconsNeedLayout];
   [listView layoutIconsIfNeeded:kAnimationDuration domino:NO];

To get the SBIconListView instance containing an icon:

   id listViewForIcon(SBIcon *icon)
   {
       SBIconController *controller = [objc_getClass("SBIconController") sharedInstance];
       SBRootFolder *rootFolder = [controller valueForKeyPath:@"rootFolder"];
       NSIndexPath *indexPath = [rootFolder indexPathForIcon:icon];
       SBIconListView *listView = nil;
       [controller getListView:&listView folder:NULL relativePath:NULL forIndexPath:indexPath createIfNecessary:YES];
       return listView;
   }

Reference