ios-unity/Classes_cocos/QrCodeViewController.m
2022-11-25 15:08:47 +08:00

83 lines
2.4 KiB
Objective-C

//
// QrCodeViewController.m
// Unity-iPhone
//
// Created by zhl on 2022/11/24.
//
#import "QrCodeViewController.h"
#include "LBXScanNative.h"
@interface QrCodeViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *scanImg;
@property (weak, nonatomic) IBOutlet UIView *container;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *closeBtn;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@end
@implementation QrCodeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[_closeBtn addTarget:self action:@selector(dismissSelf:) forControlEvents:UIControlEventTouchUpInside];
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)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (!_imgScan) {
_scanImg.backgroundColor = [UIColor grayColor];
if (_content) {
CGSize _size = _scanImg.frame.size;
_imgScan = [LBXScanNative createQRWithString:_content QRSize:_size];
}
}
_titleLabel.text = _tipTitle;
_scanImg.image = _imgScan;
if (_autosave) {
[self saveToPhotoLibrary];
}
}
// save qr image to Camera Roll album
-(void) saveToPhotoLibrary {
UIGraphicsBeginImageContextWithOptions(self.container.bounds.size, NO, 0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.container.layer renderInContext:ctx];
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(newImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (error) {
NSLog(@"保存失败");
} else {
NSLog(@"保存成功");
}
}
-(void)dismissSelf:(UIButton *)button{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end