2013-02-07 33 views
1

我創建了一個自定義視圖(UIView的一個子類),其目的是將靜態背景圖像,靜態邊框/框架疊加以及幾個可以旋轉,拉伸和拖動的較小圖像放在一起該視圖(在將整個視圖導出爲圖像之前)。你如何確保一個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中添加了我的視圖(當佔位符沒有框架時,由於我不知道的原因),以及後來的時候(當然,它不起作用)。

我錯過了什麼? (難道我連走了這個正確的方式?)

回答

0

我最後由AutoResizeMasks設置爲

UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | 
UIViewAutoresizingFlexibleRightMargin | UIViewAutoResizingFlexibleBottomMargin 

而且ContentModes還設置

UIViewContentModeScaleAspectFit 
解決了這個
相關問題