Commit 9bfb76fe authored by jzhang's avatar jzhang

增加权限弹窗

parent 7c18d702
......@@ -44,6 +44,10 @@
EA14360528E0BF1900FFBE72 /* DemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA14360428E0BF1900FFBE72 /* DemoViewController.swift */; };
EA14360828E0CA3100FFBE72 /* LanguageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA14360628E0CA3100FFBE72 /* LanguageCell.swift */; };
EA14360928E0CA3100FFBE72 /* LanguageCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = EA14360728E0CA3100FFBE72 /* LanguageCell.xib */; };
EAD8102728E207A4002A86C9 /* MyTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD8102628E207A4002A86C9 /* MyTools.swift */; };
EAD8102928E207EF002A86C9 /* PermissionAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD8102828E207EF002A86C9 /* PermissionAlertView.swift */; };
EAD8102B28E207FA002A86C9 /* PermissionAlertView.xib in Resources */ = {isa = PBXBuildFile; fileRef = EAD8102A28E207FA002A86C9 /* PermissionAlertView.xib */; };
EAD8102D28E20A54002A86C9 /* PermissionAlertVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD8102C28E20A54002A86C9 /* PermissionAlertVC.swift */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -101,6 +105,10 @@
EA14360428E0BF1900FFBE72 /* DemoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoViewController.swift; sourceTree = "<group>"; };
EA14360628E0CA3100FFBE72 /* LanguageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguageCell.swift; sourceTree = "<group>"; };
EA14360728E0CA3100FFBE72 /* LanguageCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LanguageCell.xib; sourceTree = "<group>"; };
EAD8102628E207A4002A86C9 /* MyTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyTools.swift; sourceTree = "<group>"; };
EAD8102828E207EF002A86C9 /* PermissionAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionAlertView.swift; sourceTree = "<group>"; };
EAD8102A28E207FA002A86C9 /* PermissionAlertView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PermissionAlertView.xib; sourceTree = "<group>"; };
EAD8102C28E20A54002A86C9 /* PermissionAlertVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionAlertVC.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -163,7 +171,11 @@
694B85BB2848EB4C009BEDE1 /* AppDelegate.swift */,
694B85BD2848EB4C009BEDE1 /* SceneDelegate.swift */,
694B85BF2848EB4C009BEDE1 /* ViewController.swift */,
EAD8102828E207EF002A86C9 /* PermissionAlertView.swift */,
EAD8102A28E207FA002A86C9 /* PermissionAlertView.xib */,
EA14360428E0BF1900FFBE72 /* DemoViewController.swift */,
EAD8102C28E20A54002A86C9 /* PermissionAlertVC.swift */,
EAD8102628E207A4002A86C9 /* MyTools.swift */,
697B07EC284F2E5C0051FC23 /* CompleteVC.swift */,
692EC419284C81700043E3EA /* ViewModel.swift */,
EA14360628E0CA3100FFBE72 /* LanguageCell.swift */,
......@@ -277,6 +289,7 @@
692EC421284C8D6F0043E3EA /* french.json in Resources */,
694B85C52848EB4E009BEDE1 /* Assets.xcassets in Resources */,
EA14360928E0CA3100FFBE72 /* LanguageCell.xib in Resources */,
EAD8102B28E207FA002A86C9 /* PermissionAlertView.xib in Resources */,
694B85C32848EB4C009BEDE1 /* Main.storyboard in Resources */,
692EC423284C8D6F0043E3EA /* spanish.json in Resources */,
692EC422284C8D6F0043E3EA /* english.json in Resources */,
......@@ -332,13 +345,16 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
EAD8102928E207EF002A86C9 /* PermissionAlertView.swift in Sources */,
694B85C02848EB4C009BEDE1 /* ViewController.swift in Sources */,
694B85BC2848EB4C009BEDE1 /* AppDelegate.swift in Sources */,
697B07ED284F2E5C0051FC23 /* CompleteVC.swift in Sources */,
EA14360528E0BF1900FFBE72 /* DemoViewController.swift in Sources */,
692EC41A284C81700043E3EA /* ViewModel.swift in Sources */,
EAD8102D28E20A54002A86C9 /* PermissionAlertVC.swift in Sources */,
EA14360828E0CA3100FFBE72 /* LanguageCell.swift in Sources */,
694B85BE2848EB4C009BEDE1 /* SceneDelegate.swift in Sources */,
EAD8102728E207A4002A86C9 /* MyTools.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -5,6 +5,8 @@
// Created by jzhang on 2022/9/26.
//
import AVFoundation
import Flutter
import Popover
import UIKit
import ZJTableViewManager
......@@ -13,12 +15,57 @@ class DemoViewController: UIViewController {
fileprivate var popover: Popover!
fileprivate var manager: ZJTableViewManager!
lazy var vm: ViewModel = .init()
@IBOutlet var titleL: UILabel!
@IBOutlet var stepL1: UILabel!
@IBOutlet var stepL2: UILabel!
@IBOutlet var stepL3: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
overrideUserInterfaceStyle = .light
UIApplication.shared.isIdleTimerDisabled = true
navigationController?.setNavigationBarHidden(true, animated: false)
updateUI()
}
fileprivate func updateUI() {
titleL.text = vm.landingPageTitle
stepL1.text = vm.landingPageStep1
stepL2.text = vm.landingPageStep2
stepL3.text = vm.landingPageStep3
}
/// 切换根据选择的语言更新UI
/// - Parameter language: 语言
fileprivate func updateUI(language: ViewModel.Language) {
vm.language = language
updateUI()
}
/// 提示权限问题
fileprivate func showPermissionChalenge() {
let sb = UIStoryboard(name: "Main", bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: "PermissionAlertVC") as! PermissionAlertVC
vc.modalPresentationStyle = .overCurrentContext
vc.vm = vm
present(vc, animated: true)
}
/// 检查权限
/// - Returns: 是否有相机权限
fileprivate func checkCameraPermission() -> Bool? {
let cameraAuthorizationStatus = AVCaptureDevice.authorizationStatus(for: .video)
switch cameraAuthorizationStatus {
case .notDetermined:
return nil
case .authorized:
return true
default:
showPermissionChalenge()
return false
}
}
}
......@@ -43,8 +90,8 @@ extension DemoViewController {
currentItem = item
}
item.setSelectionHandler { [weak self] (callBackItem: LanguageCellItem) in
self?.vm.language = callBackItem.language
self?.popover.dismiss()
self?.updateUI(language: callBackItem.language)
}
}
currentItem?.select()
......@@ -53,28 +100,3 @@ extension DemoViewController {
popover.show(tableView, fromView: sender)
}
}
func hexStringToUIColor(hex: String) -> UIColor {
var cString: String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if cString.hasPrefix("#") {
cString.remove(at: cString.startIndex)
}
if (cString.count) != 6 {
return UIColor.gray
}
var rgbValue: UInt64 = 0
Scanner(string: cString).scanHexInt64(&rgbValue)
return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}
let mainColor = hexStringToUIColor(hex: "F58685")
let blackColor = hexStringToUIColor(hex: "322D31")
//
// MyTools.swift
// BreastFeedingDemo
//
// Created by jzhang on 2022/9/27.
//
import Foundation
import UIKit
protocol XibLoadable: UIView {
static func xibLoad() -> Self
}
extension XibLoadable {
static func xibLoad() -> Self {
return Bundle.main.loadNibNamed("\(Self.self)", owner: nil, options: nil)?.first as! Self
}
}
func hexStringToUIColor(hex: String) -> UIColor {
var cString: String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if cString.hasPrefix("#") {
cString.remove(at: cString.startIndex)
}
if (cString.count) != 6 {
return UIColor.gray
}
var rgbValue: UInt64 = 0
Scanner(string: cString).scanHexInt64(&rgbValue)
return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}
let mainColor = hexStringToUIColor(hex: "F58685")
let blackColor = hexStringToUIColor(hex: "322D31")
//
// PermissionAlertVC.swift
// BreastFeedingDemo
//
// Created by jzhang on 2022/9/27.
//
import UIKit
class PermissionAlertVC: UIViewController {
@IBOutlet var permissionPanel: UIView!
@IBOutlet var permissionTitle: UILabel!
@IBOutlet var permissionText: UILabel!
@IBOutlet var permissionOKBtn: UIButton!
var vm: ViewModel = .init()
override func viewDidLoad() {
super.viewDidLoad()
permissionText.text = vm.cameraText1
permissionTitle.text = vm.cameraText
permissionOKBtn.setTitle(vm.cameraButtonText, for: .normal)
permissionPanel.layer.cornerRadius = 8
permissionPanel.clipsToBounds = true
// Do any additional setup after loading the view.
}
@IBAction func dismissAction(_: Any) {
dismiss(animated: true)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
//
// PermissionAlertView.swift
// BreastFeedingDemo
//
// Created by jzhang on 2022/9/27.
//
import UIKit
class PermissionAlertView: UIView, XibLoadable {}
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="PermissionAlertView" customModule="BreastFeedingDemo" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="414" height="250"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="131.8840579710145" y="308.03571428571428"/>
</view>
</objects>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment