美文网首页
UIScrollView相关

UIScrollView相关

作者: 楼上那只猫 | 来源:发表于2017-09-22 00:02 被阅读16次

If you intend to support zoom in your scroll view, the most common technique is to use a single subview that encompasses the entire contentSize of the scroll view and then add additional subviews to that view. This allows you to specify the single ‘collection’ content view as the view to zoom, and all its subviews will zoom according to its state

如果想要让 scrollview 支持缩放功能,通常最常用的实现方式是添加一个大的子 view, 该子 view 填充所有 contsize, 然后在该子 view 上添加 subview, 缩放该 view, 那么子 view 会跟着缩放

To add padding, use the contentInset
property to specify a buffer area around the content of the scroll view. One way of thinking of it is that it makes the scroll view content area larger without changing the size of the subview or the size of the view’s content

设置 contentInset 属性,可以使 scrollview 展示内容的区域变大(上下左右留白)

the scroll indicator scrolls over any content displayed in the areas that are within the area defined by contentInset

设置 contentInset 的负面效果是会使滚动条超出内容区域,为了解决这个问题,可以设置 scrollIndicatorInsets 属性

Scrolling to a Specific Offset

改变 offset 的方法

setContentOffset:animated:
调用该方法,代理会接收 scrollViewDidScroll: 信息,如果animated 参数为 YES, 代理会连续接收scrollViewDidScroll: 信息,在动画结束后,还会接收scrollViewDidEndScrollingAnimation:信息

直接设置 contentOffset 属性,会触发代理接收一次scrollViewDidScroll: 信息

指定滚动到某个区域
scrollRectToVisible:animated:

Scroll to Top

Your application enables this behavior by implementing the delegate method the scroll view property scrollViewShouldScrollToTop: and return YES. This delegate method allows fine-grained control over which scroll view will scroll to the top if there are multiple scroll views on the screen at one time by returning the scroll view to scroll.
When scrolling is complete, the delegate is sent a scrollViewDidScrollToTop: message, specifying the scroll view

scrollViewShouldScrollToTop:
If the delegate doesn’t implement this method, YES
is assumed. For the scroll-to-top gesture (a tap on the status bar) to be effective, the scrollsToTop
property of the UIScrollView
must be set to YES

scrollViewDidScrollToTop:
The scroll view sends this message when it finishes scrolling to the top of the content. It might call it immediately if the top of the content is already shown. For the scroll-to-top gesture (a tap on the status bar) to be effective, the scrollsToTop
property of the UIScrollView
must be set to YES.

缩放

要实现手势缩放,需要实现 scrollview 的代理方法,实现下面的方法

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.imageView;   //需要缩放的视图
}

设置最小和最大缩放倍数

self.scrollView.minimumZoomScale=0.5;
self.scrollView.maximumZoomScale=6.0;

缩放结束后调用该代理方法

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale {

}

相关文章

网友评论

      本文标题:UIScrollView相关

      本文链接:https://www.haomeiwen.com/subject/vqhxextx.html