Skip to content

Commit

Permalink
View layout fix
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed May 13, 2015
1 parent 3c9460a commit 0269db6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 14 additions & 0 deletions pxSVG-TestApp/ViewController.m
Expand Up @@ -89,4 +89,18 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat w = collectionView.bounds.size.width;
CGFloat c = round(w/160);
CGFloat i = (w-c+1)/c;
return (CGSize){i,i};
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
[self.collectionViewLayout invalidateLayout];
}

@end
11 changes: 6 additions & 5 deletions pxSVG/pxSVGView.m
Expand Up @@ -33,17 +33,17 @@ - (void)layoutSublayersOfLayer:(CALayer *)layer
[self.svgLayer setFrame:self.layer.bounds];
CATransform3D tr = CATransform3DIdentity;
CGRect c = self.svgLayer.contentRect;
CGFloat
scx = c.size.width/self.bounds.size.width,
scy = c.size.height/self.bounds.size.height,
sc;
switch (self.contentMode) {
case UIViewContentModeScaleAspectFit: {
CGFloat
scx = c.size.width/self.bounds.size.width,
scy = c.size.height/self.bounds.size.height,
case UIViewContentModeScaleAspectFit:
sc = MAX(scx,scy);
tr = CATransform3DMakeScale(1/sc, 1/sc, 1);
tr = CATransform3DTranslate(tr, -c.size.width/2, -c.size.height/2, 0);
tr = CATransform3DTranslate(tr, self.bounds.size.width/2, self.bounds.size.height/2, 0);
break;
}
default: break;
}
[self.svgLayer setTransform:tr];
Expand All @@ -52,6 +52,7 @@ - (void)layoutSublayersOfLayer:(CALayer *)layer
- (void)svgLayerDidLoadImage:(pxSVGLayer *)svgLayer
{
[self setNeedsLayout];
[self layoutSublayersOfLayer:self.layer];
[self setNeedsDisplay];
if ([self.svgDelegate respondsToSelector:@selector(svgViewDidLoadImage:)])
[self.svgDelegate svgViewDidLoadImage:self];
Expand Down

0 comments on commit 0269db6

Please sign in to comment.