UIEvent详解:远程控制,运动控制和触摸事件

来源:互联网 发布:2015网络电视剧排行榜 编辑:程序博客网 时间:2024/05/11 15:20

UIEvent对象代表一个事件。在iOS中,主要有三种事件:触摸事件,运动事件,远程控制事件。远程控制事件主要是外部辅助设备或者耳机的远程命令,例如控制音乐声音的大小,或者下一首歌。运动事件主要是晃动设备等。

触摸事件包括一个或者多个触摸(touches), 每个触摸有一个UITouch对象表示。当触摸事件发生时,系统会通过触摸处理的逻辑找到合适的responder并把UIEvent对象传递过去。responder通过touchesBegan:withEvent:等方法去接收UIEvent对象。

UIResponser都能接收事件,系统提供了几个方法接收UIEvent

    //触摸    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {    }        override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {    }        override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {    }    //摇晃相关    override func motionBegan(motion: UIEventSubtype, withEvent event: UIEvent) {    }        override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent) {    }        override func motionCancelled(motion: UIEventSubtype, withEvent event: UIEvent) {    }        //远程控制相关    override func remoteControlReceivedWithEvent(event: UIEvent) {    }

获得事件的触摸

//所有的触摸let allTouches = event.allTouches()//获得UIView的触摸event.touchesForView(self.view)//获得UIWindow的触摸event.touchesForWindow(self.view.window!)
事件的时间戳

//事件的时间戳event.timestamp

事件中特定手势的触摸

let gesture = UITapGestureRecognizer(target: self, action: "Tap")event.touchesForGestureRecognizer(gesture)

三种事件类型

UIEventTypeTouchesUIEventTypeMotionUIEventTypeRemoteControl

事件亚类型

UIEventSubtypeNone                              = 0,//触摸事件的亚类型        UIEventSubtypeMotionShake                       = 1,//摇晃        UIEventSubtypeRemoteControlPlay                 = 100,//播放UIEventSubtypeRemoteControlPause                = 101,//暂停UIEventSubtypeRemoteControlStop                 = 102,//停止UIEventSubtypeRemoteControlTogglePlayPause      = 103,//播放和暂停切换UIEventSubtypeRemoteControlNextTrack            = 104,//下一首UIEventSubtypeRemoteControlPreviousTrack        = 105,//上一首UIEventSubtypeRemoteControlBeginSeekingBackward = 106,//开始后退UIEventSubtypeRemoteControlEndSeekingBackward   = 107,//结束后退UIEventSubtypeRemoteControlBeginSeekingForward  = 108,//开始快进UIEventSubtypeRemoteControlEndSeekingForward    = 109,//结束快进


0 0
原创粉丝点击