2013-10-10 134 views
4

我有難以處理的設計,適合兩種3.5英寸iPhone和5英寸的iPhone(模擬器)的佈局。我檢查了自動佈局,所有的佈局都很完美。不過,我現在需要使用UIScrollView,因此需要取消選中要使用的自動佈局。處理iPhone的3.5英寸和IPhone 4英寸顯示屏(UIScrollView中)

還與iPhone 4英寸顯示器觀看的佈局時,其增加了約60像素到的UIScrollView的頂部。

是否有更好的方法來做到這一點(不取消自動佈局設置了滾動型)?所以我可以支持iPhone 4.

//to set up the scrollview 
[self.scrollView setScrollEnabled:YES]; 
[self.scrollView setContentSize:CGSizeMake(320, 800)]; 

但是,它不會滾動,直到我取消選中自動佈局。有一個更好的方法嗎?

+0

請把您的問題的截圖爲更好地理解。 –

+1

'UIScrollView,因此需要取消自動佈局才能使用'爲什麼是這樣? –

+0

@ArkadiuszHolko由於某種原因,滾動視圖不會不取消選中自動佈局。然而,我可能做錯了。 – DevC

回答

0

試試這個(它解決我的問題):

scrollView addConstraint:[NSLayoutConstraint constraintWithItem:lastSubView 
             attribute:NSLayoutAttributeRight 
             relatedBy:NSLayoutRelationEqual 
              toItem:scrollView 
             attribute:NSLayoutAttributeRight 
             multiplier:1.0 
              constant:0]]; 

參考:UIScrollView doesn't use autolayout constraints

0

UIScrollView使用Autolayout時略有不同。你需要做一些修改。你的回答是here

+0

感謝您的評論,我想實現什麼建議,但我覺得我有點失落,我創建了一個子視圖,並添加它做滾動視圖,而不是添加UI元素到它'[滾動視圖addConstraint:[NSLayoutConstraint constraintWithItem:lastSubView屬性:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:scrollView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0]];' – DevC

+0

現在你在使用自動佈局嗎?檢查自動佈局?如果您使用自動佈局,您是否添加了'translatesAutoresizingMaskIntoConstraints = NO;'? – iOS

+0

我在使用AutoLayout,但我沒有使用'translatesAutoresizingMaskIntoConstraints = NO;',這會使它工作嗎? – DevC

0

你可以做這樣的事情你UIScrollView frame。按照下面的CGRect將框架分配給滾動視圖。

CGRect rect=[[UIScreen mainScreen] bounds]; 

希望這會對你有用。

+0

請你再解釋一下嗎? – DevC

1

嘗試自動調整大小,

self.scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin); 
+0

對不起,這沒有工作,謝謝你。 – DevC

相關問題