Scroll View Programming Guide for iOS 筆記

1.ScrollView經過拖動或者輕彈實現scroll不須要子類或者代理。只有UIScrollView的content size須要經過程序設置,其餘都能用Interface Builder設置 app

   2.只須要少許的額外配置ScrollView就能達到基本的滾動功能。 ui

   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.  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);" orm

   5.當scroll view的size配置完成以後,應用程序能夠添加須要的子視圖在view content上,能夠經過程序或者interface builder插入。 事件

   6.經過程序的方法建立scroll view以下 ip

      - (void)loadView { ci

         CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame]; it

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

         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.

相關文章
相關標籤/搜索