Scroll View Programming Guide for iOS 笔记

1.ScrollView通过拖动或者轻弹实现scroll不需要子类或者代理。只有UIScrollView的content size需要通过程序设置,其他都能用Interface Builder设置

   2.只需要少量的额外配置ScrollView就能达到基本的滚动功能。

   3.ScrollView可以加在controller或者其他view上面。只有两个步骤需要配置scroll view。(1)contentSize属性,表示可以滚动的内容,This specifies the size of the scrollable area.(2)必须添加view或者views作为显示的内容。

   4.Even though the UIScrollView inspector in Interface Builder allows you to set many of the properties of the scroll view instance, you are still responsible for setting the contentSize property, which defines the size of the scrollable area, in your application code. 

    If you’ve connected the scroll view to the view property of a controller instance (typically the File’s Owner), initializing the contentSize property occurs in the controller’s viewDidLoad method。"tempScrollView.contentSize=CGSizeMake(1280,960);"

   5.当scroll view的size配置完成之后,应用程序可以添加需要的子视图在view content上,可以通过程序或者interface builder插入。

   6.通过程序的方法创建scroll view如下

      - (void)loadView {

         CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];

         scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];

         scrollView.contentSize=CGSizeMake(758,320);

 

         // do any further configuration to the scroll view

         // add a view, or views, as a subview of the scroll view.

 

// release scrollView as self.view retains it

         self.view=scrollView;

         [scrollView release];

         }

   7.如果需要scroll view支持放大(zoom),最常见的方法是使用一个单一的子视图包括整个scroll view 的contentSize,之后再在此视图上添加其他的视图,这允许你指定单一的‘collection’view 作为view来zoom,同时所有的子视图都能根据自己的状态来zoom。

     如果不需要支持zoom,then whether your scroll view uses a single subview (with or without its own subviews) or multiple subviews is an application dependent decision.

   8.配置Scroll View Content Size, Content Inset(内容插图), And Scroll Indicators(滚动指示)

     您可能要添加围绕scroll view内容的边缘填充,typically at the top and bottom of the content so that controllers and toolbars don’t interfere with seeing the entire scroll view content. 

     To add padding to your application must set the contentInset 属性 of the scroll view.contentInset属性指定一个buffer area在scroll view content周围, that it makes the scroll view content area larger without changing the size of the subview or the size of the view’s content.

     The contentInset 属性 is a UIEdgeInsets struct with the fields top, bottom, left, right.

   9.contentInset属性的设置。(64,44,0,0) for the contentInset属性 results in an additional buffer area that is 64 pixels at the top of the content (20 pixels for the status bar and 44 pixels for the navigation controller)

     and 44 pixels at the bottom (the height of the toolbar). Setting contentInset to these values allows displaying the navigation control and toolbar on screen, yet still allows scrolling to display the entire content of the scroll view.

     scrollView.contentInset=UIEdgeInsetsMake(64.0,0.0,44.0,0.0);

   10.scrollView.scrollIndicatorInsets=UIEdgeInsetsMake(64.0,0.0,44.0,0.0); (设置滚动条的位置)

   11.a flick手势:手迅速的向上或者下滑动,在没有停止滑动的时候,当手指再次按到时,立即停止滑动。

   12.程序控制滚动(scrolling)Scroll To Top:点击状态栏,scroll view回到顶部,如果想实现这个,实现代理方法scrollViewShouldScrollToTop返回YES,当完成时,给代理发送scrollViewDidScrollToTop: 消息。

   13.scroll view的四种状态属性:tracking, dragging, decelerating,zooming。

   14.简单的方法:跟踪scroll action的开始和结束

      如果应用程序只对scrolling的开始和结束感兴趣,只用实现代理方法的子集。实现scrollViewWillBeginDragging:方法接受dragging开始的通知。To determine when scrolling is complete you must implement two delegate methods: scrollViewDidEndDragging:willDecelerate: and scrollViewDidEndDecelerating:. 

  Scrolling is completed either when the delegate receives the scrollViewDidEndDragging:willDecelerate: message with NO as the decelerate parameter, or when your delegate receives the scrollViewDidEndDecelerating: method. In either case, scrolling is complete。

   15.完整的过程delegate 消息序列

      当用户触摸screen时,tracking序列开始,tracking属性立即被设置为YES,在用户的手指没有离开screen时,其值一直为YES,无论其是否移动。

      如果用户的手指保持静止,内容视图响应触摸事件,它应该处理,此序列已完成。如果用户的手指移动,序列继续,scroll view的dragging属性设置为YES,向代理发送scrollViewWillBeginDragging:消息。

      当用户drag(拖动)手指,将向代理发送scrollViewDidScroll:消息,当scroll继续时,此消息也会不断的发送,可以实现这个方法来查看scroll view的contentOffset的属性,去锁定top-left corner of the scroll view bounds的位置。contentOffset属性始终是滚动视图的左上角的当前位置,无论是滚动与否。

      如果用户使用一个flick手势,tracking属性设置为NO,用户的手指离开screen,视图开始scroll,在此时,代理收到scrollViewDidEndDragging:willDecelerate: 消息。在减速过程中,deceleration参数被设置成YES,减慢的速度有属性decelerationRate控制,缺省值为 UIScrollViewDecelerationRateNormal,它使scroll在一个合理的时间内。

      As a view decelerates, the decelerating property of the scroll view is YES.

      如果用户拖动(drag),停止拖动,手指离开屏幕,代理会收到scrollViewDidEndDragging:willDecelerate: 消息,但是参数deceleration被设置为NO,decelerating属性也被设置为NO。

      当用户手指从静止中离开screen时,scrollViewDidEndDragging:willDecelerate: 消息也发送给代理。

      scroll view提供返弹当用户拖拉到边界时,此时也发送scrollViewDidEndDragging:willDecelerate: 消息,deceleration参数为YES。

      无论什么条件收到的scrollViewDidEndDragging:willDecelerate: 消息,如果decelerate参数为YES,代理将收到scrollViewWillBeginDecelerating:消息,在减速过程中,代理将不断的收到scrollViewDidScroll:消息,尽管tracking and dragging的值已被设置为NO,decelerating属性将继续为YES。

      最后当减速完成时,代理收到scrollViewDidEndDecelerating:消息,decelerating属性设置为NO,序列完成。

   16. tracking          YES if the user’s finger is in contact with the device screen.

         dragging          YES if the user’s finger is in contact with the device screen and has moved.

         decelerating      YES if the scroll view is decelerating as a result of a flick gesture, or a bounce from dragging beyond the scroll view frame.

         zooming           YES if the scroll view is tracking a pinch gesture to change its zoomScale property..

         contentOffset     A CGPoint value that defines the top-left corner of the scroll view bounds.

 

转载自:http://blog.sina.com.cn/s/blog_67419c420100phyf.html


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值