- prevent onscreen widget moved out of superView bounds
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user