Skip to content

Commit

Permalink
修正在最新的iOS里有使用Scene的情况下不能正确的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckDeck committed Nov 6, 2020
1 parent a577804 commit e52d72d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
29 changes: 18 additions & 11 deletions Sources/ViewChaos.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ extension UIWindow:UIActionSheetDelegate {
viewChaos.tag = -1000
self.addSubview(viewChaos)
self.addObserver(self, forKeyPath: "rootViewController", options: NSKeyValueObservingOptions.new, context: nil)
viewChaos.addViewInfoView()
let def = UserDefaults.standard
def.set(true, forKey: "ShakeEnable")
def.synchronize()
Expand All @@ -103,8 +104,11 @@ extension UIWindow:UIActionSheetDelegate {

open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if let v = self.viewWithTag(-1000){
v.removeFromSuperview()
self.addSubview(v)
if let viewchaos = v as? ViewChaos{
v.removeFromSuperview()
self.addSubview(v)
viewchaos.addViewInfoView()
}
}


Expand Down Expand Up @@ -350,11 +354,11 @@ extension UIView{

class ViewChaos: UIView {
var isTouch:Bool //是否下在触摸中
var left,top:Float //右 上
var vcleft,vctop:Float //右 上
weak var previousViewTouch:UIView?
weak var viewTouch:UIView?
var viewBound:UIView //显示抓去View的边界
var windowInfo:UIWindow
var windowInfo:UIView
var lblInfo:UILabel
var viewChaosInfo:ViewChaosInfo?
var viewNeat:ViewNeat?
Expand All @@ -370,18 +374,18 @@ class ViewChaos: UIView {
viewBound.layer.zPosition = CGFloat(Float.greatestFiniteMagnitude)

let infoTop:CGFloat = UIDevice.isNotchScreen ? 36 : 0
windowInfo = UIWindow(frame: CGRect(x: 0, y: infoTop, width: UIScreen.main.bounds.width, height: 50))
windowInfo = UIView(frame: CGRect(x: 0, y: infoTop, width: UIScreen.main.bounds.width, height: 50))
windowInfo.backgroundColor = UIColor(red: 0.0, green: 0.898, blue: 0.836, alpha: 0.7)
windowInfo.isHidden = true
windowInfo.chaosName = "windowInfo"
windowInfo.windowLevel = UIWindow.Level.alert
// windowInfo.windowLevel = UIWindow.Level.alert
lblInfo = UILabel(frame: windowInfo.bounds)
lblInfo.numberOfLines = 2
lblInfo.backgroundColor = UIColor.clear
lblInfo.lineBreakMode = NSLineBreakMode.byCharWrapping
lblInfo.autoresizingMask = [UIView.AutoresizingMask.flexibleHeight,UIView.AutoresizingMask.flexibleWidth]
left = 0
top = 0
vcleft = 0
vctop = 0

super.init(frame: CGRect.zero)
self.frame = CGRect(x: UIScreen.main.bounds.width-35, y: 100, width: 30, height: 30)
Expand Down Expand Up @@ -414,6 +418,9 @@ class ViewChaos: UIView {
fatalError("init(coder:) has not been implemented")
}

func addViewInfoView() {
superview?.insertSubview(windowInfo, at: 1000)
}

@objc func handleTraceShow(_ notif:Notification){ //如果关了ViewChaosInfo,就会显示出来
self.isHidden = false
Expand Down Expand Up @@ -585,8 +592,8 @@ class ViewChaos: UIView {

let touch = touches.first
let point = touch?.location(in: self) //这个坐标是这个圆本身的坐标
left = Float(point!.x)
top = Float(point!.y)
vcleft = Float(point!.x)
vctop = Float(point!.y)
let topPoint = touch?.location(in: self.window)

if let view = topView(self.window!, point: topPoint!)
Expand Down Expand Up @@ -619,7 +626,7 @@ class ViewChaos: UIView {
}
let touch = touches.first
let point = touch?.location(in: self.window)
self.frame = CGRect(x: point!.x - CGFloat(left), y: point!.y - CGFloat(top), width: self.frame.size.width, height: self.frame.size.height)//这是为了精准定位.,要处理当前点到top和left的位移
self.frame = CGRect(x: point!.x - CGFloat(vcleft), y: point!.y - CGFloat(vctop), width: self.frame.size.width, height: self.frame.size.height)//这是为了精准定位.,要处理当前点到top和left的位移
if let view = topView(self.window!, point: point!)
{
let fm = self.window?.convert(view.bounds, from: view)
Expand Down
10 changes: 5 additions & 5 deletions Sources/ViewChaosInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class ViewChaosInfo: UIView,UITableViewDataSource,UITableViewDelegate {
var arrSuperView:[ViewChaosObject]?
var arrSubview:[ViewChaosObject]?
var isTouch:Bool = false
var vwTop:CGFloat = 0
var vwLeft:CGFloat = 0
var vcTop:CGFloat = 0
var vcLeft:CGFloat = 0
var originFrame:CGRect?
var arrTrace:[[String:AnyObject]]?
var viewTrackBorderWith:CGFloat?
Expand Down Expand Up @@ -838,8 +838,8 @@ class ViewChaosInfo: UIView,UITableViewDataSource,UITableViewDelegate {
isTouch = true
if let touch = touches.first{
let p = touch.location(in: self)
vwLeft = p.x
vwTop = p.y
vcLeft = p.x
vcTop = p.y
}
}

Expand All @@ -851,7 +851,7 @@ class ViewChaosInfo: UIView,UITableViewDataSource,UITableViewDelegate {
if let touch = touches.first
{
let p = touch.location(in: self.window)
self.frame = CGRect(x: p.x - vwLeft, y: p.y - vwTop, width: self.frame.size.width, height: self.frame.size.height)
self.frame = CGRect(x: p.x - vcLeft, y: p.y - vcTop, width: self.frame.size.width, height: self.frame.size.height)
}
}

Expand Down
12 changes: 6 additions & 6 deletions Sources/ViewNeat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ViewNeat: UIView,ColorPickerDelegate {
var currentColor:UIColor
var vRockerArea:UIView
var vRocker: UIView
var left,top:Float //右 上
var vcleft,vctop:Float //右 上
var scaleX = 1
var scaleY = 1
var scale:Int = 1
Expand All @@ -104,8 +104,8 @@ class ViewNeat: UIView,ColorPickerDelegate {
segItemMenu = UISegmentedControl(items: ["LeftTop","RightBottom"])
vRockerArea = UIView()
vRocker = UIView()
left = 0
top = 0
vcleft = 0
vctop = 0
lblViewInfo = UILabel()
originFrame = CGRect.zero
currentColor = UIColor.clear
Expand Down Expand Up @@ -251,8 +251,8 @@ class ViewNeat: UIView,ColorPickerDelegate {
{
if point.x > 0 && point.x < vRocker.frame.size.width && point.y > 0 && point.y < vRocker.frame.size.height{
isTouch = true
left = Float(point.x)
top = Float(point.y)
vcleft = Float(point.x)
vctop = Float(point.y)
if timer!.isValid{
timer?.fire()
timer?.resumeChaosTimer()
Expand All @@ -268,7 +268,7 @@ class ViewNeat: UIView,ColorPickerDelegate {
}
let touch = touches.first
if let point = touch?.location(in: vRockerArea){
var newFrame = CGRect(x: point.x - CGFloat(left), y: point.y - CGFloat(top), width: vRocker.frame.size.width, height: vRocker.frame.size.height)
var newFrame = CGRect(x: point.x - CGFloat(vcleft), y: point.y - CGFloat(vctop), width: vRocker.frame.size.width, height: vRocker.frame.size.height)
if newFrame.origin.x <= 0{
newFrame.origin.x = 0
}
Expand Down

0 comments on commit e52d72d

Please sign in to comment.