今天偶爾看到了一個之前沒注意過的UIView
的屬性exclusiveTouch
缎谷,在這里記錄一下济赎。
文檔中對這個屬性的解釋:
A Boolean value that indicates whether the receiver handles touch events exclusively.
Setting this property to YES causes the receiver to block the delivery of touch events to other views in the same window. The default value of this property is NO.
這個屬性主要是解決多個控件同時響應事件的問題,將exclusiveTouch
設置為YES
的話可以阻止同一個window
中其他控件與他響應,默認為NO
。
舉個例子:頁面中有按鈕ButtonA 和 ButtonB,點擊ButtonA會push該頁面评腺,點擊ButtonB則會pop該頁面,如果同時點擊這個按鈕的話頁面就會連續(xù)出現pop和push的效果淑掌。如果設置了exclusiveTouch
為YES
的話則可以避免發(fā)生這種事情蒿讥。
可以使用 appearance
在APPDelegate中對UIView進行統(tǒng)一的設置。
[[UIView appearance] setExclusiveTouch:YES];