美文网首页
iOS 淘票票截图反馈功能实现

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

作者: SoaringHeart | 来源:发表于2019-08-16 15:56 被阅读0次
    效果图.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
    
    

    源码

    相关文章

      网友评论

          本文标题:iOS 淘票票截图反馈功能实现

          本文链接:https://www.haomeiwen.com/subject/wflqsctx.html