国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

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

發(fā)布時(shí)間:2021-09-27 17:50 來(lái)源:億速云 閱讀:0 作者:小新 欄目: 開(kāi)發(fā)技術(shù)

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

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

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

//注冊截屏通知

[[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{/* 分享代碼*

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系QQ:712375056 進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。

iOS
日韩高清不卡无码AV| 国内精品国产三级国产AV| AV永久免费网站入口| 激情综合丁香五月| 国产精品毛片无遮挡高清| 不卡无码人妻一区二区三区|