UIScrollView 不能滚动

来源:互联网 发布:java 引用其他文件 编辑:程序博客网 时间:2024/05/24 05:48

1.最常见的原因是 
  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 theviewDidLoad method and perform your tasks there.



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

-(void)viewDidLayoutSubviews{

    [superviewDidLayoutSubviews];

    self.myScrollView.frame = CGRectMake(00kScreenWidthkScreenHeight-44);

    self.myScrollView.contentSize = CGSizeMake(kScreenWidthkMyScrollViewHeight);

 

}



 要多页显示且能左右滑动,把UIImageView嵌入到UIScrollView中,并将UIScrollView的pagingEnabled属性设为YES,即可实现整页的滑动。

0 0
原创粉丝点击