该方法在官方的解释是这样的
Scrolls a specific area of the content so that it is visible in the receiver.
Declaration
SWIFT : func scrollRectToVisible(_ rect: CGRect ,
animated animated : Bool)
OBJECTIVE-C :
- (void)scrollRectToVisible:(CGRect)rect
animated:(BOOL)animated
Parameters
rect A rectangle defining an area of the content view. The rectangle should be in the coordinate space of the scroll view.
animated YES (if the scrolling should be animated.), NO (if it should be immediate.)
Discussion
This method scrolls the content view so that the area defined by rect is just visible inside the scroll view. If the area is already visible, the method does nothing.
Availability
Available in iOS 2.0 and later.
使用这个方法可以将滚动到特定的区域,让视图可见。
rect的作用是定义要可见视图的区域,这个区域需要在滚动视图的坐标空间中。animated就不需要多解释了。
还有一点需要注意的是该可见视图是在这个滚动视图的范围而当前不可见,如果当前已经可见了,那么这个方法将不会做任何事情。