2013-10-10 133 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

相关问题