I created a UICollectionView
which is horizontal and vertically. It has different UICollectionViewCells
. Everything is layouted correctly. Now I am trying to make it zoomable
. The UICollectionViewCells
are resized correctly too. Every time the UIPinchGesture
occures, I set the itemSize
inside the UICollectionViewLayout
dependend on the scale
.
TestLayout *layout = (TestLayout *) self.collectionViewLayout;
CGSize newItemSize = CGSizeMake(_sizeItem.width * gesture.scale,
_sizeItem.height * gesture.scale);
[layout setItemSize:newItemSize];
Here you can see the method setItemSize I am calling inside my CustomLayout.
- (void)setItemSize:(CGSize)itemSize
{
if (CGSizeEqualToSize(self.itemSize, itemSize)) return;
_itemSize = itemSize;
// [self prepareLayout];
[self invalidateLayout];
}
My problem is know, all items resize
to the right bottom and I don't know how to focus exactly on the element my UIPinchGesture
was on.
I tried to change the contentOffset
every time the gesture
occures like this:
CGPoint posInView = [gesture locationInView:self];
CGPoint pointPinchTouch = CGPointMake(posInView.x - self.contentOffset.x,
posInView.y - self.contentOffset.y);
CGPoint newOffset = CGPointMake(self.contentOffset.x * (gesture.scale * 2),
self.contentOffset.y * (gesture.scale * 2));
[self setContentOffset:newOffset animated:NO];
But I never managed to stay on the CGPoint
my UIPinchGesture
was executed.
Furthermore when scrolling
on the whole UICollectionView
, my contentOffset
is still {0,0}
when the scroll
didn't end. So start pinching I always end up in the top left corner.
Because the UICollectionView
seems not to be designed to be used horizontal and vertical at the same time, thats why I also can't use the delegate
methods of UIScrollView
for zooming
.
Maybe somebody can tell me how to solve this problem.