IOS Uiscrollview Proxy method

Source: Internet
Author: User
<span id="Label3"></p><span style="font-size: 16px; font-family: 宋体"><span style="font-size: 16px; font-family: 宋体">Methods && properties:</span></span><p><p><span style="font-size: 16px; font-family: 宋体">Monitor the current scrolling position (default Cgpointzero)</span></p></p><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-built_in">CGPoint contentOffset; - (<span class="hljs-keyword">void)setContentOffset:(<span class="hljs-built_in">CGPoint)contentOffset animated:(<span class="hljs-built_in">BOOL)animated;</span></span></span></span></code></span></pre></pre><p><p><span style="font-size: 16px; font-family: 宋体">The size of the scrolling range (default Cgsizezero)</span></p></p><pre class="hljs nginx"><pre class="hljs nginx"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-title">CGSize contentSize; </span></code></span></pre></pre><p><p><span style="font-size: 16px; font-family: 宋体">Position of the view in ScrollView (uiedgeinsetszero)</span></p></p><pre class="hljs nginx"><pre class="hljs nginx"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-title">UIEdgeInsets contentInset; </span></code></span></pre></pre><p><p><span style="font-size: 16px; font-family: 宋体">Set up protocols</span></p></p><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-keyword">id<<span class="hljs-built_in">UIScrollViewDelegate> delegate;</span></span></code></span></pre></pre><p><p><span style="font-size: 16px; font-family: 宋体">Specifies whether the control can scroll only in one Direction (default is No)</span></p></p><pre class="hljs nginx"><pre class="hljs nginx"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-title">BOOL directionalLockEnabled; </span></code></span></pre></pre><p><p><span style="font-size: 16px; font-family: 宋体">Controls whether the control encounters a bounce (default = yes)</span></p></p><pre class="hljs nginx"><pre class="hljs nginx"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-title">BOOL bounces; </span></code></span></pre></pre><p><p><span style="font-size: 16px; font-family: 宋体">Controls whether a border is bouncing vertically (default is no, if Yes,bounces is yes)</span></p></p><pre class="hljs nginx"><pre class="hljs nginx"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-title">BOOL alwaysBounceVertical; </span></code></span></pre></pre><p><p><span style="font-size: 16px; font-family: 宋体">Controls whether the border is bouncing horizontally (default is no, if Yes,bounces is yes)</span></p></p><pre class="hljs nginx"><pre class="hljs nginx"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-title">BOOL alwaysBounceHorizontal;</span></code></span></pre></pre><p><p><span style="font-size: 16px; font-family: 宋体">Controls whether the control is full-page flip (default is No)</span></p></p><pre class="hljs nginx"><pre class="hljs nginx"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-title">BOOL pagingEnabled; </span></code></span></pre></pre><p><p><span style="font-size: 16px; font-family: 宋体">Controls whether controls can scroll</span></p></p><pre class="hljs nginx"><pre class="hljs nginx"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-title">BOOL scrollEnabled;</span></code></span></pre></pre><p><p><span style="font-size: 16px; font-family: 宋体">Controls whether to display scroll bars in the horizontal direction</span></p></p><pre class="hljs nginx"><pre class="hljs nginx"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-title">BOOL showsHorizontalScrollIndicator; </span></code></span></pre></pre><p><p><span style="font-size: 16px; font-family: 宋体">Controls whether to display scroll bars in a vertical direction</span></p></p><pre class="hljs nginx"><pre class="hljs nginx"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-title">BOOL showsVerticalScrollIndicator;</span></code></span></pre></pre><p><p><span style="font-size: 16px; font-family: 宋体">Specify the position of the scrollbar in Scrollerview</span></p></p><pre class="hljs nginx"><pre class="hljs nginx"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-title">UIEdgeInsets scrollIndicatorInsets; </span></code></span></pre></pre><p><p><span style="font-size: 16px; font-family: 宋体">Set the style of the scroll bar</span></p></p><pre class="hljs nginx"><pre class="hljs nginx"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-title">UIScrollViewIndicatorStyle indicatorStyle; </span></code></span></pre></pre><span style="font-size: 16px; font-family: 宋体"><span style="font-size: 16px; font-family: 宋体">Uiscrollviewdelegate Detailed</span></span><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size:16px; font-family: Song body"><code class="c"><span class="hljs-comment">/ The method is called when The/scrollview is Scrolled. This method is called by any change in the value of Offset. That is, called multiple times during Scrolling-(<span class="hljs-keyword">void) scrollviewdidscroll: (<span class="hljs-built_in">uiscrollview *) Scrollview{<span class="hljs-built_in">nslog (<span class="hljs-string">@ "scrollviewdidscroll"); <span class=" hljs-built_in ">cgpoint point=scrollview<span class=" hljs-variable ">.contentoffset; <span class="hljs-built_in">nslog (<span class="hljs-string">@ "%f,%f", point<span class="hljs-variable">.x,point <span class="hljs-variable">.y); <span class="hljs-comment">//from which you can read the Contentoffset property to determine where it is scrolled to. <span class="hljs-comment">//note: When the Contentsize attribute is less than the frame, it will not be set to scroll} </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></code></span></pre></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size:16px; font-family: Song body"><code class="c"><span class="hljs-comment">/ /when ScrollView is scaled, the method is Called. Call back multiple times during Scaling-(<span class="hljs-keyword">void) scrollviewdidzoom: (<span class="hljs-built_in">uiscrollview *) Scrollview{<span class="hljs-built_in">nslog (<span class="hljs-string">@ "scrollviewdidscroll"); <span class=" Hljs-keyword ">float value=scrollview<span class=" hljs-variable ">.zoomscale; <span class="hljs-built_in">nslog (<span class="hljs-string">@ "%f", value);} </span> </span> </span> </span> </span> </span> </span></span></span></code></span></pre></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size:16px; font-family: Song body"><code class="c"><span class="hljs-comment">/ /when You start scrolling the view, the method is Executed. An effective slide (start sliding, slide A short distance, as long as the finger does not release, only one slide), only one Time. -(<span class="hljs-keyword">void) scrollviewwillbegindragging: (<span class="hljs-built_in">UIScrollView *) Scrollview{<span class="hljs-built_in">nslog (<span class="hljs-string">@ "scrollviewwillbegindragging");} </span> </span></span></span></span></code></span></pre></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-comment">// 滑动scrollView,并且手指离开时执行。一次有效滑动,只执行一次。<span class="hljs-comment">// 当pagingEnabled属性为YES时,不调用,该方法- (<span class="hljs-keyword">void)scrollViewWillEndDragging:(<span class="hljs-built_in">UIScrollView *)scrollView withVelocity:(<span class="hljs-built_in">CGPoint)velocity targetContentOffset:(<span class="hljs-keyword">inout <span class="hljs-built_in">CGPoint *)targetContentOffset{ <span class="hljs-built_in">NSLog(<span class="hljs-string">@"scrollViewWillEndDragging");}</span></span></span></span></span></span></span></span></span></code></span></pre></pre><pre class="hljs objectivec"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-comment">Slide the view, call the method when the finger leaves the screen that Moment. A valid slide, executed only once.<span class="hljs-comment"><span class="hljs-comment">//decelerate, Referring to whether the view will continue to scroll forward (some distance) after our fingers leave that moment, tested, decelerate=yes-(<span class=" Hljs-keyword ">void) scrollviewdidenddragging: (<span class=" hljs-built_in ">uiscrollview *) ScrollView Willdecelerate: (<span class="hljs-built_in">bool) decelerate{<span class="hljs-built_in">NSLog ( <span class="hljs-string">@ "scrollviewdidenddragging"); <span class="hljs-keyword">if (decelerate) {<span class="hljs-built_in">nslog (<span class="hljs-string">@ " Decelerate "); }<span class="hljs-keyword">else{<span class="hljs-built_in">nslog (<span class="hljs-string">@ "no decelerate");} <span class="hljs-built_in">cgpoint point=scrollview<span class="hljs-variable">.contentoffset; <span class=" hljs-built_in ">nslog (<span class=" hljs-string ">@"%f,%f ", point<span class=" hljs-variable ">.x,point<span class=" Hljs-variable ">.y); </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></code></span></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size:16px; font-family: Song body"><code class="c"><span class="hljs-comment">/ /slide deceleration when the method is Called. -(<span class="hljs-keyword">void) scrollviewwillbegindecelerating: (<span class="hljs-built_in">UIScrollView *) Scrollview{<span class="hljs-built_in">nslog (<span class="hljs-string">@ "scrollviewwillbegindecelerating"); Span class= "hljs-comment" >//the method after the scrollviewdidenddragging method. }</span></span></span></span></span></code></span></pre></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size:16px; font-family: Song body"><code class="c"><span class="hljs-comment">/ /scrolling view deceleration is complete, the method is called when scrolling stops. A valid slide, executed only once. -(<span class="hljs-keyword">void) scrollviewdidenddecelerating: (<span class="hljs-built_in">UIScrollView *) Scrollview{<span class="hljs-built_in">nslog (<span class="hljs-string">@ "scrollviewdidenddecelerating"); [_scrollview setcontentoffset:cgpointmake (<span class="hljs-number">0, <span class="hljs-number">500) animated:< Span class= "hljs-literal" >yes];} </span> </span> </span> </span> </span> </span> </span> </code></span><code class="c"> </code> </pre></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size:16px; font-family: Song body"><code class="c"><span class="hljs-comment">/ /when The scrolling view animation is complete, call the method, and if there is no animation, then the method will not be Called-(<span class="hljs-keyword">void) scrollviewdidendscrollinganimation: (<span class="hljs-built_in">uiscrollview *) scrollview{<span class="hljs-built_in">nslog (<span class="hljs-string">@ " Scrollviewdidendscrollinganimation "); <span class="hljs-comment">//effective Animation method is: <span class="hljs-comment">//-(void) setcontentoffset: (cgpoint) Contentoffset animated: (BOOL) Animated method <span class="hljs-comment">//-(void) scrollrecttovisible: (cgrect) rect Animated: (BOOL) animated method} </span> </span> </span> </span> </span> </span> </span> </span> </code> </span> </pre></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size:16px; font-family: Song body"><code class="c"><span class="hljs-comment">/ /returns the UIView object that will be Scaled. To execute multiple times-(<span class="hljs-built_in">uiview *) viewforzoominginscrollview: (<span class="hljs-built_in"> Uiscrollview *) scrollview{<span class="hljs-built_in">nslog (<span class="hljs-string">@ " Viewforzoominginscrollview "); <span class="hljs-keyword">return <span class="hljs-keyword">self<span class="hljs-variable">.imgView;} </span> </span> </span></span></span></span></span></span></code></span></pre></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size:16px; font-family: Song body"><code class="c"><span class="hljs-comment">/ /when you are about to start scaling, execute the Method. Once a valid scaling is Performed. -(<span class="hljs-keyword">void) scrollviewwillbeginzooming: (<span class="hljs-built_in">UIScrollView *) ScrollView withview: (<span class="hljs-built_in">uiview *) view{<span class="hljs-built_in">nslog (<span class=" Hljs-string ">@" scrollviewwillbeginzooming ")} </span> </span> </span> </span> </span> </span> </code> </span> </pre></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size:16px; font-family: Song body"><code class="c"><span class="hljs-comment">/ The method is called when the zoom is finished, and the scaling is small back to Minimumzoomscale and Maximumzoomscale (we may go beyond the zoom range). -(<span class="hljs-keyword">void) scrollviewdidendzooming: (<span class="hljs-built_in">UIScrollView *) ScrollView withview: (<span class="hljs-built_in">uiview *) view atscale: (<span class="hljs-keyword">float) scale{ Span class= "hljs-built_in" >nslog (<span class="hljs-string">@ "scrollviewdidendzooming");} </span> </span> </span> </span> </span></span></code></span></pre></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-comment">// 指示当用户点击状态栏后,滚动视图是否能够滚动到顶部。需要设置滚动视图的属性:_scrollView.scrollsToTop=YES;- (<span class="hljs-built_in">BOOL)scrollViewShouldScrollToTop:(<span class="hljs-built_in">UIScrollView *)scrollView{ <span class="hljs-keyword">return <span class="hljs-literal">YES;}</span></span></span></span></span></code></span></pre></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-comment">// 当滚动视图滚动到最顶端后,执行该方法- (<span class="hljs-keyword">void)scrollViewDidScrollToTop:(<span class="hljs-built_in">UIScrollView *)scrollView{ <span class="hljs-built_in">NSLog(<span class="hljs-string">@"scrollViewDidScrollToTop");}</span></span></span></span></span></code></span></pre></pre><span style="font-size: 16px; font-family: 宋体"><span style="font-size: 16px; font-family: 宋体">Tip: Determine if the Uiscrollview is scrolling up or down</span></span><pre class="hljs objectivec"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-keyword"><span class="hljs-keyword">int _lastposition; <span class="hljs-comment">//a variable define in Headfile-(<span class="hljs-keyword">void) scrollviewdidscroll: ( Span class= "hljs-built_in" >uiscrollview *) scrollview{<span class="hljs-keyword">int currentpostion = scrollView< Span class= "hljs-variable" >.contentoffset<span class="hljs-variable">.y; <span class="hljs-keyword">if (currentpostion-_lastposition > <span class="hljs-number">25) {_lastPosition = currentpostion; <span class="hljs-built_in">nslog (<span class="hljs-string">@ "scrollup now");} <span class="hljs-keyword">else <span class="hljs-keyword">if (_lastposition-currentpostion > <span class=" Hljs-number ">25) {_lastposition = currentpostion; <span class="hljs-built_in">nslog (<span class="hljs-string">@ "scrolldown now");}} <span class="hljs-comment">//25 can be any number, can be set according to their own needs. </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span> </span></code></span></pre><pre class="hljs objectivec"><span style="font-size: 16px; font-family: 宋体"><code class="c"><span class="hljs-comment">Upgrade: does not bounce when reaching the top or bottom-(<span class="hljs-keyword">Void) Scrollviewdidscroll: (<span class="hljs-built_in">Uiscrollview *) scrollview{<span class="hljs-keyword">int currentpostion = ScrollView<span class="hljs-variable">. contentoffset<span class="hljs-variable"><span class="hljs-variable">.y; <span class="hljs-keyword">if (currentpostion-_lastposition > <span class="hljs-number">20 && Currentpostion > <span class="hljs-number">0) {<span class="hljs-comment">//this place plus currentpostion > 0) _ Lastposition = currentpostion; <span class="hljs-built_in">nslog (<span class="hljs-string">@ "scrollup now");} <span class="hljs-keyword">else <span class="hljs-keyword">if (_lastposition-currentpostion > <span class=" Hljs-number ">20" && (currentpostion <= scrollview<span class="hljs-variable">.contentsize<span class=" Hljs-variable ">.height-scrollview<span class=" hljs-variable ">.bounds<span class=" hljs-variable ">.size<span class="hljs-variable">.height-<span class="hljs-number">20)) {_lastposition = currentpostion; <span class=" hljs-built_in ">nslog (<span class=" hljs-string ">@" scrolldown now ")}} </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></span></span></span></span> </span></span></span></span></span></span></code></span></pre><p><p><span style="font-size: 16px; font-family: 宋体"><code class="c"> </code></span></p></p><p><p>IOS Uiscrollview Proxy method</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.