該方法在官方的解釋是這樣的
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.
使用這個(gè)方法可以將滾動(dòng)到特定的區(qū)域,讓視圖可見(jiàn)。
rect的作用是定義要可見(jiàn)視圖的區(qū)域,這個(gè)區(qū)域需要在滾動(dòng)視圖的坐標(biāo)空間中。animated就不需要多解釋了。
還有一點(diǎn)需要注意的是該可見(jiàn)視圖是在這個(gè)滾動(dòng)視圖的范圍而當(dāng)前不可見(jiàn),如果當(dāng)前已經(jīng)可見(jiàn)了,那么這個(gè)方法將不會(huì)做任何事情。