- prevent onscreen widget moved out of superView bounds

This commit is contained in:
TrueZhuanjia
2025-07-20 16:22:33 +08:00
parent 0d3149a696
commit f22d05a34e
+8 -3
View File
@@ -1134,10 +1134,15 @@ import UIKit
let currentLocation: CGPoint
if OnScreenWidgetView.editMode {currentLocation = touch.location(in: superview)}
else {currentLocation = touch.location(in: self)}
let offsetX = currentLocation.x - latestTouchLocation.x;
let offsetY = currentLocation.y - latestTouchLocation.y;
let outOfBoundsX = center.x+offsetX > (self.superview?.bounds.width)! || center.x+offsetX < 0
let outOfBoundsY = center.y+offsetY > (self.superview?.bounds.height)! || center.y+offsetY < 0
center = CGPoint(x: outOfBoundsX ? center.x : center.x+offsetX, y: outOfBoundsY ? center.y : center.y+offsetY)
let offsetX = currentLocation.x - latestTouchLocation.x
let offsetY = currentLocation.y - latestTouchLocation.y
center = CGPoint(x: center.x + offsetX, y: center.y + offsetY)
latestTouchLocation = currentLocation
// center = currentLocation;
//NSLog("x coord: %f, y coord: %f", self.frame.origin.x, self.frame.origin.y)