ios-unity/Classes_cocos/SimpleQRViewController.m
2022-12-07 16:02:13 +08:00

76 lines
2.3 KiB
Objective-C

//
// SimpleQRViewController.m
// Unity-iPhone
//
// Created by zhl on 2022/12/7.
//
#import "SimpleQRViewController.h"
#include "LBXScanNative.h"
#include "UIUtils.h"
#import "ToastManager.h"
@interface SimpleQRViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *scanImg;
@property (weak, nonatomic) IBOutlet UIView *container;
@end
@implementation SimpleQRViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissBgView)];
[self.view addGestureRecognizer:tapGesture];
UITapGestureRecognizer *bgViewTapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(copyContent)];
[self.container addGestureRecognizer:bgViewTapGesture];
self.container.backgroundColor = [UIColor whiteColor];
self.container.layer.shadowOffset = CGSizeMake(0, 2);
self.container.layer.shadowRadius = 2;
self.container.layer.shadowColor = [UIColor blackColor].CGColor;
self.container.layer.shadowOpacity = 0.5;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (void)copyContent{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = self.content;
[ToastManager showToastWithMessage:@"Content copied to clipboard."];
}
- (void)dismissBgView {
[UIView animateWithDuration:0.5 animations:^{
self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.1];
self.container.alpha = 0;
} completion:^(BOOL finished) {
[self dismissViewControllerAnimated:NO completion:nil];
}];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.container.alpha = 1;
if (!_imgScan) {
_scanImg.backgroundColor = [UIColor grayColor];
if (_content) {
CGSize _size = _scanImg.frame.size;
_imgScan = [LBXScanNative createQRWithString:_content QRSize:_size];
}
_scanImg.image = _imgScan;
}
}
@end