- prevent onscreen widget moved out of superView bounds
This commit is contained in:
1 parent
0d3149a696
commit
f22d05a34e
1 file changed
+8
-3
@@ -1135,9 +1135,14 @@ import UIKit
|
|||||||
if OnScreenWidgetView.editMode {currentLocation = touch.location(in: superview)}
|
if OnScreenWidgetView.editMode {currentLocation = touch.location(in: superview)}
|
||||||
else {currentLocation = touch.location(in: self)}
|
else {currentLocation = touch.location(in: self)}
|
||||||
|
|
||||||
let offsetX = currentLocation.x - latestTouchLocation.x
|
let offsetX = currentLocation.x - latestTouchLocation.x;
|
||||||
let offsetY = currentLocation.y - latestTouchLocation.y
|
let offsetY = currentLocation.y - latestTouchLocation.y;
|
||||||
center = CGPoint(x: center.x + offsetX, y: center.y + offsetY)
|
|
||||||
|
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)
|
||||||
|
|
||||||
latestTouchLocation = currentLocation
|
latestTouchLocation = currentLocation
|
||||||
// center = currentLocation;
|
// center = currentLocation;
|
||||||
//NSLog("x coord: %f, y coord: %f", self.frame.origin.x, self.frame.origin.y)
|
//NSLog("x coord: %f, y coord: %f", self.frame.origin.x, self.frame.origin.y)
|
||||||
|
|||||||
Reference in new issue
Block a user