Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS 6.0: UICollectionView doesn't respect clipsToBounds with pagingEnabled
    primarykey
    data
    text
    <p><strong>Background</strong></p> <p>I am implementing a <code>UICollectionView</code> (for the first time) in an effort to achieve a paged horizontal scroll view of tiles. I'd like each tile to show in the center of the frame with it's sister tiles partially visible to the left and right (something like the page selector in the Safari app). I'm interested in using the <code>UICollectionView</code> to take advantage of built-in cell dequeueing and would rather not use a rotated <code>UITableView</code>.</p> <p><strong>Issue</strong></p> <p>The issue I'm finding is that when using <code>pagingEnabled = YES</code> and <code>clipsToBounds = NO</code>, the <code>UICollectionView</code> removes cells outside the <code>collectionView</code> frame (they're not in the <code>visibleCells</code> array) as soon as paging is complete. Can anyone provide advice on how to achieve the effect of displaying previews of the sister tiles while maintaining this basic setup? Or am I approaching this incorrectly?</p> <p><strong>Screenshots</strong></p> <p><em>start</em> <img src="https://dl.dropbox.com/u/91715/stackoverflow/start.png" alt="start"> <em>scrolling</em> <img src="https://dl.dropbox.com/u/91715/stackoverflow/scrolling.png" alt="scrolling"> <em>end</em> <img src="https://dl.dropbox.com/u/91715/stackoverflow/end.png" alt="end"></p> <p>The <strong>scrolling</strong> screen is exactly correct. But in the start and end shots I want there to be green visible in the blue margins.</p> <p>Here's what's in my AppDelegate.m (credit to <a href="http://mobile.tutsplus.com/tutorials/iphone/uicollectionview-layouts">tutsplus.com</a> for the basic setup here):</p> <pre><code>#import "AppDelegate.h" @interface ViewController : UICollectionViewController @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"ID"]; [self.view setBackgroundColor:[UIColor blueColor]]; // pad the collection view by 20 px UIEdgeInsets padding = UIEdgeInsetsMake(20.0, 20.0, 20.0, 20.0); [self.collectionView setFrame:UIEdgeInsetsInsetRect(self.view.frame, padding)]; // set pagingEnabled and clipsToBounds off [self.collectionView setPagingEnabled:YES]; [self.collectionView setClipsToBounds:NO]; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 5; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ID" forIndexPath:indexPath]; UILabel *label = [[UILabel alloc] initWithFrame:cell.bounds]; label.textAlignment = NSTextAlignmentCenter; label.text = [NSString stringWithFormat:@"%d", indexPath.row]; [label setBackgroundColor:[UIColor greenColor]]; [cell.contentView addSubview:label]; return cell; } @end @implementation AppDelegate { ViewController *vc; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // setup the UICollectionViewFlowLayout UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.itemSize = CGSizeMake(280, 280); layout.minimumInteritemSpacing = 0; layout.minimumLineSpacing = 0; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; // add a custom UICollectionViewController to the window vc = [[ViewController alloc] initWithCollectionViewLayout:layout]; self.window.rootViewController = vc; self.window.backgroundColor = [UIColor yellowColor]; [self.window makeKeyAndVisible]; return YES; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload