真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

iOS怎么實(shí)現(xiàn)捕捉截屏事件并展示截圖效果

這篇文章主要為大家展示了“iOS怎么實(shí)現(xiàn)捕捉截屏事件并展示截圖效果”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“iOS怎么實(shí)現(xiàn)捕捉截屏事件并展示截圖效果”這篇文章吧。

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),禹會(huì)企業(yè)網(wǎng)站建設(shè),禹會(huì)品牌網(wǎng)站建設(shè),網(wǎng)站定制,禹會(huì)網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,禹會(huì)網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。

iOS7之后,蘋果開放出一個(gè)通知:UIApplicationUserDidTakeScreenshotNotification,截屏?xí)r系統(tǒng)就會(huì)發(fā)出這個(gè)通知,需要你注冊(cè)這個(gè)通知,就能捕捉到截屏圖片。

下面的代碼,實(shí)現(xiàn)的是用戶截屏后,捕獲到截屏圖片,展示出來(lái):

//注冊(cè)截屏通知

[[NSNotificationCenter defaultCenter] addObserver:self    selector:@selector(getScreenShot:)    name:UIApplicationUserDidTakeScreenshotNotification object:nil];

截屏后捕捉到事件:

- (void)getScreenshot:(NSNotification *)notification{ NSLog(@"捕捉截屏事件"); //獲取截屏圖片 UIImage *image = [UIImage imageWithData:[self imageDataScreenShot]]; //顯示圖片 UIImageView *imgV = [[UIImageView alloc]initWithImage:image]; imgV.frame = [UIScreen mainScreen].bounds; UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; backView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.8]; UIButton *shareBtn = [UIButton buttonWithType:UIButtonTypeSystem]; shareBtn.titleLabel.font = [UIFont systemFontOfSize:17.0]; [shareBtn setTintColor:[UIColor whiteColor]]; shareBtn.frame = CGRectMake(SCREEN_WIDTH/5,SCREEN_HEIGHT ,SCREEN_WIDTH*3/5,50); [shareBtn.layer setMasksToBounds:YES]; [shareBtn.layer setBorderWidth:1]; shareBtn.layer.cornerRadius = 6; [shareBtn setTitle:@"分享給好友" forState:UIControlStateNormal]; shareBtn.backgroundColor = [SouFunIMUtilityHelper colorWithHexString:@"#B22222"]; [shareBtn addTarget:self action:@selector(shareBtn:) forControlEvents:UIControlEventTouchUpInside]; [backView addSubview:imgV]; [backView addSubview:shareBtn]; UIWindow *window = [UIApplication sharedApplication].keyWindow; [window addSubview:backView]; [UIView animateWithDuration:1.0 animations:^{  imgV.transform = CGAffineTransformMakeScale(0.8, 0.8);  shareBtn.transform = CGAffineTransformMakeTranslation(0, -50); }]; //3秒后消失 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{  [backView removeFromSuperview]; });}

獲取截屏圖片data:

- (NSData *)imageDataScreenShot{ CGSize imageSize = CGSizeZero; imageSize = [UIScreen mainScreen].bounds.size; UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(); for (UIWindow *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 ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])  {   [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];  }  else  {   [window.layer renderInContext:context];  }  CGContextRestoreGState(context); } UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return UIImagePNGRepresentation(image);}

按鈕點(diǎn)擊事件:

-(void)shareBtn:(UIButton *)sender{/* 分享代碼*/}

以上是“iOS怎么實(shí)現(xiàn)捕捉截屏事件并展示截圖效果”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!


本文名稱:iOS怎么實(shí)現(xiàn)捕捉截屏事件并展示截圖效果
文章鏈接:http://weahome.cn/article/psisjp.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部