Learning the basics of UIScrollView

ぃ、小莉子 提交于 2019-11-27 11:07:23
Ben Stiglitz

Here is a scroll view guide from Apple

The basic steps are:

  1. Create a UIScrollView and a content view you want to put inside (in your case a UIImageView).
  2. Make the content view a subview of the scroll view.
  3. Set the content size of the scrollview to the frame size of the content view. This is a very important step that people often omit.
  4. Put the scroll view in a window somewhere.

As for the paging behavior, check out UIScrollView’s pagingEnabled property. If you need to scroll by less than a whole page you’ll need to play tricks with clipsToBounds, sort of the reverse of what is happening in this StackOverflow question.

UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 

NSInteger viewcount= 4; 
for (int i = 0; i <viewcount; i++) 
{ 
CGFloat y = i * self.view.frame.size.height; 
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, y,self.view.frame.size.width, self .view.frame.size.height)];      
view.backgroundColor = [UIColor greenColor]; 
[scrollview addSubview:view]; 
[view release]; 
}
scrollview.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height *viewcount); 

For more information Create UIScrollView programmatically

Dickey Singh

New 3/26/2013 I stumbled on an easier way to do this without code (contentSize)

https://stackoverflow.com/a/15649607/1705353

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!