[英]How do you ensure that a UIView shrinks down to the size of its superview?
我正在創建一個自定義視圖(UIView的子類),其目的是將靜態背景圖像,靜態邊框/框架覆蓋圖以及幾個可以在視圖周圍旋轉,拉伸和拖動的較小圖像組合在一起(在將整個視圖導出為圖像之前)。
我被困在從另一個視圖中顯示此自定義視圖。 這些圖像來自具有高分辨率的iPhone相機,到目前為止,我唯一能做的就是截取大部分圖像或將我的視線移到屏幕的末端。 我需要能夠在菜單項等旁邊顯示它,而無需編輯圖像(以便可以完整格式發送圖像)。
我還將圖像添加到全屏視圖,並且它仍然不會改變大小。
我正在如下初始化視圖
- (id)initWithImage:(UIImage *)image
{
self = [super init];
if (self) {
[self setClipsToBounds:YES];
[self setAutoresizesSubviews:YES];
[self setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
_image = image;
_imageView = [[UIImageView alloc] initWithImage:_image];
[_imageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[self addSubview:_imageView];
}
return self;
}
我將其添加到另一個視圖
self.card = [[SGImageCard alloc] initWithImage:[SGCardDataController cardImage]];
[self.cardPlaceHolder setAutoresizesSubviews:YES];
[self.cardPlaceHolder setContentMode:UIViewContentModeScaleAspectFit];
[self.cardPlaceHolder addSubview:self.card];
該視圖也已在Interface Builder中設置,並在那里設置為自動調整其子視圖的大小和Cliptobounds(有時,我已經嘗試過兩種方法)。 我已經在viewdidload中添加了我的視圖(當占位符沒有框架,由於我不知道的原因),后來又添加了它(無論哪種方式都不起作用)。
我想念什么? (我是否已經以正確的方式解決了這個問題?)
我終於通過將AutoResizeMasks設置為
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleRightMargin | UIViewAutoResizingFlexibleBottomMargin
並將ContentModes設置為
UIViewContentModeScaleAspectFit
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.