Commit eba169b7 authored by Tobias's avatar Tobias

fix remote browsing cell image view image fitting for larger images

parent 121f84d8
......@@ -2,6 +2,7 @@
<document type="com.apple.InterfaceBuilder.AppleTV.XIB" version="3.0" toolsVersion="9527.1" systemVersion="15B42" targetRuntime="AppleTV" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9525.1"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
......@@ -26,7 +27,13 @@
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" placeholderIntrinsicWidth="300" placeholderIntrinsicHeight="169" adjustsImageWhenAncestorFocused="YES" translatesAutoresizingMaskIntoConstraints="NO" id="tHQ-sR-zn4" customClass="VLCNetworkImageView">
<rect key="frame" x="0.0" y="13" width="300" height="169"/>
<rect key="frame" x="0.0" y="40" width="300" height="142"/>
<constraints>
<constraint firstAttribute="width" secondItem="tHQ-sR-zn4" secondAttribute="height" multiplier="19:9" id="TP3-nW-8dd"/>
</constraints>
<connections>
<outlet property="aspectRatioConstraint" destination="TP3-nW-8dd" id="0SY-4J-iS5"/>
</connections>
</imageView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
......
......@@ -20,4 +20,7 @@
- (void)cancelLoading;
@property (nonatomic, readwrite) BOOL animateImageSetting;
// if set the image view replaces the constraint on image uodates with a
// constraint that has the same aspect ratio as the image
@property (nonatomic) IBOutlet NSLayoutConstraint *aspectRatioConstraint;
@end
......@@ -76,7 +76,27 @@ static NSCache *sharedImageCache = nil;
- (void)setImage:(UIImage *)image
{
[super setImage:image];
[self setNeedsUpdateConstraints];
[self invalidateIntrinsicContentSize];
}
- (void)updateConstraints
{
[super updateConstraints];
CGSize size = self.image.size;
if (self.aspectRatioConstraint && size.height && size.width) {
NSLayoutConstraint *newConstraint = [NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeHeight
multiplier:size.width/size.height
constant:0];
[self removeConstraint:self.aspectRatioConstraint];
[self addConstraint:newConstraint];
self.aspectRatioConstraint = newConstraint;
}
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment