- UIResponder是什么
可以響應(yīng)UIEvent的類,是UIApplication, UIView及UIViewController的父類。它的父類是NSObject
- 管理第一響應(yīng)者。
- 是否是第一響應(yīng)者
func isFirstResponder() -> Bool
- 成為第一響應(yīng)者
func becomeFirstResponder() -> Bool。只有當前的第一響應(yīng)者可以放棄成為第一響應(yīng)者,且這個UIResponder可以成為第一響應(yīng)者,這個UIResponder才成為第一響應(yīng)者。
若調(diào)用這個函數(shù)的是UIView的實例,那么它一定要在視圖樹(view hierarchy)上。
- 放棄成為第一響應(yīng)者
func resignFirstResponder() -> Bool
- 管理inputview
這些方法主要是為了處理輸入框或textview成為第一響應(yīng)者時的鍵盤。默認情況下,inputview是鍵盤,inputAccessoryView是鍵盤上面的view,可以達到鍵盤上面有輸入框跟著鍵盤一起出現(xiàn)或消失的效果。
也可以對其他的子類設(shè)置自己的inputview。
- (BOOL)becomeFirstResponder
{
[super becomeFirstResponder];
[self.superview addSubview:self.inputView];
return YES;
}
[button becomeFirstResponder];
//button的inputview會被加到父view上。
- 處理touch的事件
func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?)
func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?)
func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?)
func touchesEstimatedPropertiesUpdated(_ touches: Set<UITouch>)
- 處理Motion Events
只提供開始和結(jié)束的回調(diào)
func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?)
func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?)
func motionCancelled(_ motion: UIEventSubtype, with event: UIEvent?)
- 處理遠程處理事件
func remoteControlReceived(with event: UIEvent?)
更加厲害的分享
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。