在Xcode中5.0.2我創建a universal app拖着一個UIScrollView
和UIImageView
到iPhone和iPad故事板(這裏fullscreen):新增的UIScrollView,並在UIImageView的故事板 - 圖像被壓扁,並且不滾動
然後我試圖加載由下面的代碼圖像board.png
(版權維基百科共同性,Denelson83)在ViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *img = [UIImage imageNamed:@"board"];
NSLog(@"%s: img=%@ (%f x %f)", __PRETTY_FUNCTION__,
img, img.size.width, img.size.height);
_imageView.image = img;
_scrollView.contentSize = img.size;
}
但是結果被壓扁,圖像不能滾動:
-[ViewController viewDidLoad]: img=<UIImage: 0x10912d770> (1000.000000 x 961.500000)
有什麼建議嗎?我懷疑圖像在底部被切斷,因爲我運行的是3.5英寸的iPhone模擬器?如何解決這個問題呢?
UPDATE:
我想四0約束添加滾動視圖,因此,它需要整個屏幕,但是當我旋轉用CMD-箭模擬器 - 滾動視圖沒有按」噸調整大小(此處fullscreen of Xcode):
更新2:
當我改變UIImageView
「視圖模式」爲「左上」在Xcode故事板和源代碼如下:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *img = [UIImage imageNamed:@"board"];
_imageView.image = img;
_imageView.frame = CGRectMake(0, 0, img.size.width, img.size.height);
_scrollView.contentSize = img.size;
}
然後我得到下面的結果,不能滾動:
和不能旋轉或者(沒有填滿屏幕):
您是否嘗試過不同的內容模式,如「imageView.contentMode = UIViewContentModeScaleAspectFit;」?另外你的uiimageview界限是什麼? – Roecrew
1.嘗試禁用滾動視圖的'auto resize subviews'屬性。 – Eyeball
2.嘗試禁用自動佈局或進行更改之後或內部 - viewDidLayoutSubviews – Eyeball