diff --git a/pxSVG-TestApp/ViewController.m b/pxSVG-TestApp/ViewController.m index f819ae4..f979dce 100644 --- a/pxSVG-TestApp/ViewController.m +++ b/pxSVG-TestApp/ViewController.m @@ -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 diff --git a/pxSVG/pxSVGView.m b/pxSVG/pxSVGView.m index ca55e3f..ba6109e 100644 --- a/pxSVG/pxSVGView.m +++ b/pxSVG/pxSVGView.m @@ -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]; @@ -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];