1
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPrivacyAccessedAPITypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyCollectedDataTypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyTracking</key>
|
||||
<false/>
|
||||
<key>NSPrivacyTrackingDomains</key>
|
||||
<array/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,117 @@
|
||||
import UIKit
|
||||
class XdBlur {
|
||||
/// 为视图添加背景模糊效果
|
||||
/// - Parameters:
|
||||
/// - view: 需要添加模糊效果的目标视图
|
||||
/// - style: 模糊样式(Light, Dark, ExtraLight)
|
||||
/// - intensity: 模糊强度,范围 0-1
|
||||
/// - backgroundColor: 可选的背景颜色叠加
|
||||
static func applyBlur(
|
||||
to view: UIView,
|
||||
style: UIBlurEffect.Style = .light,
|
||||
intensity: CGFloat = 0.8,
|
||||
backgroundColor: UIColor? = nil
|
||||
) {
|
||||
// 移除之前可能存在的模糊效果
|
||||
view.subviews
|
||||
.filter { $0 is UIVisualEffectView }
|
||||
.forEach { $0.removeFromSuperview() }
|
||||
|
||||
// 创建模糊效果
|
||||
let blurEffect = UIBlurEffect(style: style)
|
||||
let blurView = UIVisualEffectView(effect: blurEffect)
|
||||
|
||||
// 调整模糊强度
|
||||
if #available(iOS 13.0, *) {
|
||||
let vibrancyView = UIVisualEffectView(effect:
|
||||
UIVibrancyEffect(blurEffect: blurEffect, style: .fill)
|
||||
)
|
||||
blurView.contentView.addSubview(vibrancyView)
|
||||
}
|
||||
|
||||
// 设置frame与目标视图一致
|
||||
blurView.frame = view.bounds
|
||||
blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||
|
||||
// 设置透明度控制模糊强度
|
||||
blurView.alpha = intensity
|
||||
|
||||
// 如果需要叠加背景色
|
||||
if let backgroundColor = backgroundColor {
|
||||
let colorView = UIView(frame: blurView.bounds)
|
||||
colorView.backgroundColor = backgroundColor
|
||||
colorView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||
blurView.contentView.addSubview(colorView)
|
||||
}
|
||||
|
||||
// 插入到视图底部
|
||||
view.insertSubview(blurView, at: 0)
|
||||
}
|
||||
|
||||
/// 移除背景模糊效果
|
||||
/// - Parameter view: 需要移除模糊效果的视图
|
||||
static func removeBlur(from view: UIView) {
|
||||
view.subviews
|
||||
.filter { $0 is UIVisualEffectView }
|
||||
.forEach { $0.removeFromSuperview() }
|
||||
}
|
||||
|
||||
/// 为视图添加自定义高斯模糊效果
|
||||
/// - Parameters:
|
||||
/// - view: 目标视图
|
||||
/// - radius: 模糊半径
|
||||
/// - tintColor: 颜色叠加
|
||||
static func applyCustomBlur(
|
||||
to view: UIView,
|
||||
radius: CGFloat = 10,
|
||||
tintColor: UIColor? = nil
|
||||
) {
|
||||
// 创建模糊效果
|
||||
let blurEffect = UIBlurEffect(style: .light)
|
||||
let blurView = UIVisualEffectView(effect: blurEffect)
|
||||
|
||||
// 应用额外的模糊
|
||||
let vibrancyView = UIVisualEffectView(effect:
|
||||
UIVibrancyEffect(blurEffect: blurEffect)
|
||||
)
|
||||
|
||||
blurView.frame = view.bounds
|
||||
blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||
|
||||
// 添加自定义颜色叠加
|
||||
if let tintColor = tintColor {
|
||||
let colorView = UIView(frame: blurView.bounds)
|
||||
colorView.backgroundColor = tintColor
|
||||
colorView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||
blurView.contentView.addSubview(colorView)
|
||||
}
|
||||
|
||||
view.insertSubview(blurView, at: 0)
|
||||
}
|
||||
|
||||
static func applyBlurSelf(ele: UIView ,bg:UIView, blur: CGFloat, backgroundColor: UIColor = .clear) {
|
||||
// Create snapshot of element
|
||||
UIGraphicsBeginImageContextWithOptions(ele.bounds.size, false, 0)
|
||||
ele.layer.render(in: UIGraphicsGetCurrentContext()!)
|
||||
let snapshot = UIGraphicsGetImageFromCurrentImageContext()!
|
||||
UIGraphicsEndImageContext()
|
||||
|
||||
// Create blur effect
|
||||
let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
|
||||
effectView.frame = bg.bounds
|
||||
|
||||
// Create color overlay
|
||||
let colorView = UIView(frame: bg.bounds)
|
||||
colorView.backgroundColor = backgroundColor
|
||||
colorView.alpha = blur
|
||||
|
||||
// Add views to background
|
||||
bg.addSubview(effectView)
|
||||
bg.addSubview(colorView)
|
||||
|
||||
// Set snapshot as background
|
||||
let imageView = UIImageView(image: snapshot)
|
||||
imageView.frame = bg.bounds
|
||||
bg.insertSubview(imageView, at: 0)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"deploymentTarget": "12"
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import { UIViewController, UIView, UIWindow, UIScreen, UIColor, UIBlurEffect } from 'UIKit';
|
||||
import { CGRect, CGFloat, CGPoint, CGAffineTransform, CGSize } from 'CoreFoundation';
|
||||
import { CABasicAnimation, CAMediaTimingFillMode, CATransform3DIsIdentity, CATransform3DIdentity, CATransform3DMakeTranslation, CATransform3DRotate, CATransform3DScale } from 'QuartzCore';
|
||||
import { getRootView } from "./libs/util.uts"
|
||||
import { Color } from 'SwiftUI';
|
||||
import { hexToRgb } from '../libs/color.uts'
|
||||
|
||||
|
||||
|
||||
export class xModalPage {
|
||||
contentView : UIView | null = null;
|
||||
rootWin : UIWindow;
|
||||
constructor() {
|
||||
let winsize = UIScreen.main.bounds as CGRect;
|
||||
let mainwidth = new CGRect(x = 0, y = 180, width = 300, height = 200)
|
||||
// 创建一个新的 UIWindow 实例
|
||||
let newWindow = new UIWindow(frame = mainwidth)
|
||||
// newWindow.frame = mainwidth
|
||||
this.rootWin = newWindow;
|
||||
}
|
||||
setView(ele : UniElement | null) {
|
||||
if (ele == null) return;
|
||||
let userView = ele!.getIOSView() as UIView | null
|
||||
if (userView == null) return;
|
||||
this.contentView = userView!;
|
||||
class ContentWin extends UIViewController {
|
||||
userView : UIView | null = null;
|
||||
setAddView(userViewBox : UIView | null) {
|
||||
this.userView = userViewBox;
|
||||
}
|
||||
override viewDidLoad() {
|
||||
super.viewDidLoad();
|
||||
let root = super.view as UIView;
|
||||
root.backgroundColor = UIColor.black
|
||||
if (this.userView != null) {
|
||||
let cview = this.userView! as UIView;
|
||||
cview.frame = UIScreen.main.bounds
|
||||
root.addSubview(cview)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (this.contentView == null) return;
|
||||
DispatchQueue.main.async(execute = () : void => {
|
||||
// 创建一个新的 UIViewController 实例作为模态视图控制器
|
||||
let secondViewController = new ContentWin()
|
||||
secondViewController.setAddView(this.contentView)
|
||||
// 将模态视图控制器添加到新窗口中
|
||||
this.rootWin.rootViewController = secondViewController as UIViewController
|
||||
|
||||
})
|
||||
}
|
||||
show() {
|
||||
let pageconroll = this.rootWin.rootViewController;
|
||||
if (this.contentView == null || pageconroll == null) return;
|
||||
DispatchQueue.main.async(execute = () : void => {
|
||||
this.rootWin.makeKeyAndVisible()
|
||||
let parent = UTSiOS.getCurrentViewController() as UIViewController;
|
||||
parent.present(pageconroll!, animated = true, completion = nil)
|
||||
})
|
||||
|
||||
}
|
||||
hide() {
|
||||
DispatchQueue.main.async(execute = () : void => {
|
||||
this.rootWin.rootViewController?.dismiss(animated = true, completion = nil)
|
||||
})
|
||||
}
|
||||
destroy() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export class xdBlur {
|
||||
$element : UniNativeViewElement;
|
||||
targetView : UIView | null = null;
|
||||
constructor(element : UniNativeViewElement) {
|
||||
//接收传递过来的UniNativeViewElement
|
||||
this.$element = element;
|
||||
this.targetView = new UIView()
|
||||
this.$element.bindIOSView(this.targetView!);
|
||||
}
|
||||
|
||||
setFilterBg(blur : number, bgcolor : string,ele:UniElement|null = null) {
|
||||
let colorrgba = hexToRgb(bgcolor)
|
||||
let br = (blur / 100).toFloat()
|
||||
let view = this.targetView!
|
||||
XdBlur.applyBlur(
|
||||
to = view,
|
||||
style = UIBlurEffect.Style.light,
|
||||
intensity = new CGFloat(br),
|
||||
backgroundColor = UTSiOS.colorWithString(bgcolor)
|
||||
)
|
||||
}
|
||||
public static setFilterSelfBg(ele : UniElement,bg:UniElement, blur : number, bgcolor : string) {
|
||||
let colorrgba = hexToRgb(bgcolor)
|
||||
let br = (blur / 100).toFloat()
|
||||
let view = ele.getIOSView()! as UIView
|
||||
let viewbg = bg.getIOSView()! as UIView
|
||||
|
||||
XdBlur.applyBlurSelf(ele=view,bg = viewbg, blur = new CGFloat(br), backgroundColor = UTSiOS.colorWithString(bgcolor))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { UIViewController, UIView } from 'UIKit';
|
||||
export function getRootView() : UIView {
|
||||
let parent = UTSiOS.getCurrentViewController() as UIViewController;
|
||||
let windUiview = parent.view as UIView
|
||||
return windUiview;
|
||||
}
|
||||
export function getRoot() : UIViewController {
|
||||
let parent = UTSiOS.getCurrentViewController() as UIViewController;
|
||||
return parent;
|
||||
}
|
||||
Reference in New Issue
Block a user