iOS 淘票票截图反馈功能实现

效果图.jpeg

🌰🌰:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(userDidTakeScreenshotNotification:) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [NSNotificationCenter.defaultCenter removeObserver:self name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}

- (void)userDidTakeScreenshotNotification:(NSNotification *)sender {
    UIWindow *window = UIApplication.sharedApplication.keyWindow;
    UIImage *snapshotImage = [UIImage snapshotImageWithView:window];
    // TODO: 将screenshotImage进行分享,可以调用友盟SDK或自己集成第三方SDK实现,这里就不做演示了
    UIButton *btn = [window showFeedbackView:snapshotImage title:@"求助反馈"];
    [btn addActionHandler:^(UIControl * _Nonnull control) {
        DDLog(@"%@", control);

    } forControlEvents:UIControlEventTouchUpInside];
    
}

code:

import "UIWindow+Helper.h"

@implementation UIWindow (Helper)

- (UIButton *)showFeedbackView:(UIImage *)image title:(NSString *)title{
    UIWindow *window = self;
    UIView *view = [window viewWithTag:9999];
    if (view) {
        [window bringSubviewToFront:view];
        return [window viewWithTag:992];
    }
    
    UIView *containView = ({
        CGFloat width = window.frame.size.width;
        CGFloat height = window.frame.size.height;
        
        CGSize imgSize = CGSizeMake(width/5.0, height/5.0);
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(width - imgSize.width, (height - imgSize.height - 30)/2.0, imgSize.width, imgSize.height + 30)];
        view.tag = 9999;
        view.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.6];
        
        [view addGestureSwipe:^(UIGestureRecognizer * _Nonnull reco) {
            [UIView animateWithDuration:0.35 animations:^{
                reco.view.transform = CGAffineTransformMakeTranslation(reco.view.transform.tx + imgSize.width, reco.view.transform.ty);
            } completion:^(BOOL finished) {
                if (finished) {
                    [reco.view removeFromSuperview];
                }
            }];
        } forDirection:UISwipeGestureRecognizerDirectionRight];
        
        UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, imgSize.width, imgSize.height)];
        view.tag = 991;
        imgView.image = image;
        [view addSubview:imgView];
        
        title = title ? : @"求助反馈";
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.tag = 992;
        btn.frame = CGRectMake(0, imgSize.height, imgSize.width, 30);
        [btn setTitle:title forState:UIControlStateNormal];
        [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        [view addSubview:btn];
        
        view;
    });
    [window addSubview:containView];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [containView removeFromSuperview];
    });
    
    return [window viewWithTag:992];
}

@end

源码

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 重点参考链接: View Programming Guide for iOS https://developer....
    Kevin_Junbaozi阅读 10,017评论 0 15
  • 概述 在多数移动应用中任何时候都只能有一个应用程序处于活跃状态,如果其他应用此刻发生了一些用户感兴趣的那么通过通知...
    莫离_焱阅读 11,601评论 1 8
  • 写文章[https://www.jianshu.com/writer#/] 发现[https://www.jian...
    牛小牛啊阅读 3,707评论 0 3
  • 絮絮风花夜渐寒,萧萧剑气刃无霜。 长刀映月空留恨,笑对苍天我自狂。 漠上横云十万里,依依此路望潇湘。 斜阳断臂寻仇...
    安城的真金阅读 3,017评论 0 1
  • 我们每一个人,在生活中,在人生的道路上,都需要一个领路人,就是弗洛伊德都不例外。弗洛伊德的名字众所周知,但是让他这...
    张漪纹阅读 5,282评论 0 0

友情链接更多精彩内容