UIScrollView是UIKit框架下的一個(gè)類,它繼承自UIView。
這里有幾個(gè)容易忽略的屬性,卻在一些大的應(yīng)用app內(nèi)廣泛應(yīng)用
delaysContentTouches:這個(gè)屬性默認(rèn)為YES,官方注釋如下:
default is YES. if NO, we immediately call -touchesShouldBegin:withEvent:inContentView:. this has no effect on presses。
當(dāng)改屬性為NO時(shí),手指點(diǎn)擊在scrollView上時(shí),若正好點(diǎn)擊在“可交互視圖”上,點(diǎn)擊事件也不會(huì)傳遞給子視圖,但不影響點(diǎn)擊。(“可交互視圖”即button,或添加了gesture的視圖。)簡(jiǎn)單說(shuō)就是scrollview上方一個(gè)button,當(dāng)該屬性為no時(shí),你點(diǎn)擊在button上也可以拖動(dòng)scrollview,若為yes,你點(diǎn)擊在button上就不能拖動(dòng)scrollview了!
canCancelContentTouches:這個(gè)屬性默認(rèn)為YES,官方注釋如下:
default is YES. if NO, then once we start tracking, we don't try to drag if the touch moves. this has no effect on presses。
當(dāng)屬性為NO時(shí),即使手指滑動(dòng)了,scrollview也不會(huì)滑動(dòng),這個(gè)屬性可限制上一個(gè)屬性,當(dāng)這個(gè)屬性no時(shí),上面那個(gè)屬性的設(shè)置無(wú)效!
UITableView和UICollectionView當(dāng)然也繼承了父類UIScrollView的這兩個(gè)屬性!