日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁(yè) > php開(kāi)源 > 綜合技術(shù) > 監(jiān)聽(tīng)手機(jī)截屏事件

監(jiān)聽(tīng)手機(jī)截屏事件

來(lái)源:程序員人生   發(fā)布時(shí)間:2016-07-19 13:02:40 閱讀次數(shù):3359次

猴子原創(chuàng),歡迎轉(zhuǎn)載。轉(zhuǎn)載請(qǐng)注明: 轉(zhuǎn)載自Cocos2Der-CSDN,謝謝!
原文地址: http://blog.csdn.net/cocos2der/article/details/51780954

今天無(wú)意中在百度地圖中截屏線路的時(shí)候,頂部出現(xiàn)提示我的截屏信息。這細(xì)節(jié)挺好的,省去我后面需要使用該截屏的繁瑣步驟。恰好手頭空閑會(huì),我也寫(xiě)個(gè)玩玩。哈哈哈~~

截屏在iOS7之前是需要使用小技能來(lái)獲得用戶截屏事件的,iOS7以后,apple開(kāi)放了用戶截屏通知事件,所以現(xiàn)在做起來(lái)還是挺方便的。

// This notification is posted after the user takes a screenshot (for example by pressing both the home and lock screen buttons) @available(iOS 7.0, *) public let UIApplicationUserDidTakeScreenshotNotification: String

注冊(cè)通知

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.userDidTakeScreenshot), name: UIApplicationUserDidTakeScreenshotNotification, object: nil)

代碼實(shí)現(xiàn)(swift)

/// 用戶截屏終了 func userDidTakeScreenshot() { // 當(dāng)前屏幕的image // 注意:為何不直接從相冊(cè)讀取截屏圖象 //(萬(wàn)1用戶直接謝絕可權(quán)限你不跪了,何況截屏以后,用戶可不知道你會(huì)提示,第1反應(yīng)肯定謝絕讀取相冊(cè)的權(quán)限) let image = imageWithScreenshot() let imageView = UIImageView(frame: CGRect(x: 50, y: 50, width: 320, height: 640)) imageView.image = image self.view.addSubview(imageView) } /// 獲得當(dāng)前屏幕圖片 func imageWithScreenshot() -> UIImage? { let imageData = dataWithScreenshotInPNGFormat() return UIImage(data: imageData) } /// 截取當(dāng)前屏幕 func dataWithScreenshotInPNGFormat() -> NSData { var imageSize = CGSizeZero let screenSize = UIScreen.mainScreen().bounds.size let orientation = UIApplication.sharedApplication().statusBarOrientation if UIInterfaceOrientationIsPortrait(orientation) { imageSize = screenSize } else { imageSize = CGSizeMake(screenSize.height, screenSize.width) } UIGraphicsBeginImageContextWithOptions(imageSize, false, 0) let context = UIGraphicsGetCurrentContext() for window in UIApplication.sharedApplication().windows { CGContextSaveGState(context) CGContextTranslateCTM(context, window.center.x, window.center.y) CGContextConcatCTM(context, window.transform) CGContextTranslateCTM(context, -window.bounds.size.width * window.layer.anchorPoint.x, -window.bounds.size.height * window.layer.anchorPoint.y) if orientation == UIInterfaceOrientation.LandscapeLeft { CGContextRotateCTM(context, CGFloat(M_PI_2)) CGContextTranslateCTM(context, 0, -imageSize.width) } else if orientation == UIInterfaceOrientation.LandscapeRight { CGContextRotateCTM(context, -CGFloat(M_PI_2)) CGContextTranslateCTM(context, -imageSize.height, 0) } else if (orientation == UIInterfaceOrientation.PortraitUpsideDown) { CGContextRotateCTM(context, CGFloat(M_PI)) CGContextTranslateCTM(context, -imageSize.width, -imageSize.height) } if window.respondsToSelector(#selector(UIView.drawViewHierarchyInRect(_:afterScreenUpdates:))) { window.drawViewHierarchyInRect(window.bounds, afterScreenUpdates: true) } else { window.layer.renderInContext(context!) } CGContextRestoreGState(context); } let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return UIImagePNGRepresentation(image)! }

注意:為何不直接從相冊(cè)讀取截屏圖象?
萬(wàn)1用戶直接謝絕可權(quán)限你不跪了,何況截屏以后,用戶可不知道你會(huì)提示,第1反應(yīng)肯定謝絕讀取相冊(cè)的權(quán)限。

生活不易,碼農(nóng)辛苦
如果您覺(jué)得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 欧美一区二区久久久 | 日本欧美在线 | 精品第一页 | 午夜av福利 | 中国大陆高清aⅴ毛片 | 亚洲精品二 | 欧美日韩色图 | 久久久久久亚洲精品视频 | 嫩草91| 91在线免费视频 | 国产日韩精品久久 | 欧美国产日韩一区 | 成人一级毛片 | 国产高清精品在线 | 亚洲欧美在线观看 | 久久精品123 | 久操福利视频 | 亚洲91视频 | 色爱区成人综合网 | 看黄入口 | 成人看片网 | 国产成人综合av | a级黄色录像| 久久久蜜桃一区二区人 | 黄色三级在线观看 | 成人午夜网 | 99久久无色码中文字幕婷婷 | 欧美国产日韩视频 | 久久久精彩视频 | 日韩在线欧美 | 日韩欧美在线视频一区二区三区 | 欧美日韩精品 | 日本黄xxxxxxxxx100| 欧美在线看片 | 国产精品成人av | 日韩电影精品 | 日本免费在线观看 | 美女久久网站 | 久久久久久久久久国产精品 | 亚洲日本久久 | 亚洲电影在线播放 |