iOS scrollview不能滑动的几个原因及解决方法

               

最常见的原因是 :

contentSize 这个属性,比uiscrollview的frame要小, 无需滚动, 自然就滚动不了。 scrollenabled 这个属性,标识着是否允许滚动,要言设成yes 

另外还有一些比较隐蔽的原因:

如果这个scrollView是在IB里面生成的话,还得手动设置它的contentSize,并且不能在initWithNibName:bundle:里面设置,因为:

The nib file you specify is not loaded right away. It is loaded the first time the view controller’s view is accessed. If you want to perform additional initialization after the nib file is loaded, override the viewDidLoad method and perform your tasks there.

在self.view上添加scrollview 能正常滚动,但再次添加其他的view的时候,就不能正常滚动了,必须用下面的一个方法才行,很好用。

-(void)viewDidLayoutSubviews{    [superviewDidLayoutSubviews]

猜你喜欢

转载自blog.csdn.net/qq_43668118/article/details/86356623
今日推荐