• invisible

Author Archive


UIScrollView Paging Hack

April 5th, 2009 by james

The paging property in UIScrollViews is pretty handy: for those unfamiliar, it’s the great snapping feature when leafing through images in your photo collection, for example. One unfortunate limitation is that the UIScrollView, as provided, only lets you snap on multiples of the frame size. We wanted to lay out smaller previews of images so you could see the previous and next images as well, something like this:
scroll1.png
It’s easy enough to lay out the images, but if you turn paging on then you end up snapping on every other item. The solution we use is to move our content within the scrollview so that it lines up properly when snapped, like so:
scroll2.png
This method is very simple to handle in the code: just put all the subviews into a container, set yourself as the scrollview delegate, and use the scrollViewDidScroll: callback method to set the CGAffineTransformTranslation of your container view to half the current content offset of the scrollview.

- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
  CGFloat offset = scrollView.contentOffset.x/2;
  CGAffineTransform transform = CGAffineTransformMakeTranslation(offset, 0);
  [contentView setTransform:transform];
}


The view no longer scrolls one-to-one with your finger, but flicking works quite well.


DEATH MONKEYS!

March 10th, 2009 by james

We were prepared for nazi ninja zombies, but this one took the inedible office by surprise:

Seriously, folks, get your shotguns. Chimpanzees, which are like humans but way more willing to rip out your throat, reportedly have the ability to create and stockpile weapons. It’s only a matter of time until Dr. Zaius rules us all.
Jonathan Stein, MotherJones.com

Good thing Shotgun Pro is out.
(story via John Gruber at Daring Fireball)