標籤:tor sbo phi state index click graphic oftype def
// 長按圖片識別二維碼
UILongPressGestureRecognizer *QrCodeTap = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(QrCodeClick:)];
[self.view addGestureRecognizer:QrCodeTap];
- (void)QrCodeClick:(UILongPressGestureRecognizer *)pressSender {
if (pressSender.state != UIGestureRecognizerStateBegan) {
return;//長按手勢只會響應一次
}
// MJPhoto *photo = _photos[_currentPhotoIndex];
// 再讀取
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CIImage *ciImage = [[CIImage alloc] initWithCGImage:image.CGImage options:nil];
CIContext *ciContext = [CIContext contextWithOptions:@{kCIContextUseSoftwareRenderer : @(YES)}]; // 軟體渲染
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:ciContext options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh}];// 二維碼識別
NSArray *features = [detector featuresInImage:ciImage];
if (features.count) {
for (CIQRCodeFeature *feature in features) {
NSLog(@"qrCodeUrl = %@",feature.messageString); // 列印二維碼中的資訊
qrCodeUrl = feature.messageString;
}
// 初始化彈框 第一個參數是設定距離底部的邊距
alertview = [[RomAlertView alloc] initWithMainAlertViewBottomInset:0 Title:nil detailText:nil cancelTitle:nil otherTitles:[NSMutableArray arrayWithObjects:@"儲存圖片",@"識別圖中二維碼",nil]];
alertview.tag = 10002;
// 設定彈框的樣式
alertview.RomMode = RomAlertViewModeBottomTableView;
// 設定彈框從什麼位置進入 當然也可以設定什麼位置退出
[alertview setEnterMode:RomAlertEnterModeBottom];
// 設定代理
[alertview setDelegate:self];
// 顯示 必須調用 和系統一樣
[alertview show];
} else {
NSLog(@"圖片中沒有二維碼");
}
}
#pragma mark -- RomAlertViewDelegate 彈框識別圖中二維碼
- (void)alertview:(RomAlertView *)alertview didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (alertview.tag == 10002) {
if ([alertview.otherTitles[indexPath.row] isEqualToString:@"儲存圖片"]) {
NSLog(@"儲存圖片");
[self saveButtonPressed];
}else if ([alertview.otherTitles[indexPath.row] isEqualToString:@"識別圖中二維碼"]){
NSLog(@"識別圖中二維碼");
// 隱藏
[alertview hide];
[self leftBackButtonPressed];
AppDelegate *delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
if([delegate.window.rootViewController isKindOfClass:[UITabBarController class]]){
UITabBarController *tabBarController = (UITabBarController *)delegate.window.rootViewController;
UINavigationController *navigationController = [tabBarController selectedViewController];
UIViewController *vc = navigationController.topViewController;
//對結果進行處理跳轉網頁
ADWebViewViewController *controller = [[ADWebViewViewController alloc] init];
controller.m_url = qrCodeUrl;
controller.hidesBottomBarWhenPushed = YES;
[vc.navigationController pushViewController:controller animated:YES];
}
}
}
}
iOS - 長按圖片識別圖中二維碼