Emoji UI improvements

This commit is contained in:
Ali
2023-01-24 14:25:26 +01:00
parent 52c60a3f0d
commit b92d21f9d7
33 changed files with 318 additions and 123 deletions

View File

@@ -136,21 +136,30 @@ public struct Transition {
//view.layer.position = CGPoint(x: frame.midX, y: frame.midY)
view.layer.removeAnimation(forKey: "position")
view.layer.removeAnimation(forKey: "bounds")
view.layer.removeAnimation(forKey: "bounds.size")
completion?(true)
case .curve:
let previousFrame: CGRect
if (view.layer.animation(forKey: "position") != nil || view.layer.animation(forKey: "bounds") != nil), let presentation = view.layer.presentation() {
previousFrame = presentation.frame
let previousPosition: CGPoint
let previousBounds: CGRect
if (view.layer.animation(forKey: "position") != nil || view.layer.animation(forKey: "bounds") != nil || view.layer.animation(forKey: "bounds.size") != nil), let presentation = view.layer.presentation() {
previousPosition = presentation.position
previousBounds = presentation.bounds
} else {
previousFrame = view.frame
previousPosition = view.layer.position
previousBounds = view.layer.bounds
}
view.frame = frame
//view.bounds = CGRect(origin: previousBounds.origin, size: frame.size)
//view.center = CGPoint(x: frame.midX, y: frame.midY)
let anchorPoint = view.layer.anchorPoint
let updatedPosition = CGPoint(x: frame.minX + frame.width * anchorPoint.x, y: frame.minY + frame.height * anchorPoint.y)
self.animatePosition(view: view, from: CGPoint(x: previousFrame.midX, y: previousFrame.midY), to: CGPoint(x: frame.midX, y: frame.midY), completion: completion)
self.animateBoundsSize(view: view, from: previousFrame.size, to: frame.size)
self.animatePosition(view: view, from: previousPosition, to: updatedPosition, completion: completion)
if previousBounds.size != frame.size {
self.animateBoundsSize(view: view, from: previousBounds.size, to: frame.size)
}
}
}
@@ -193,10 +202,12 @@ public struct Transition {
case .none:
view.bounds = bounds
view.layer.removeAnimation(forKey: "bounds")
view.layer.removeAnimation(forKey: "bounds.origin")
view.layer.removeAnimation(forKey: "bounds.size")
completion?(true)
case .curve:
let previousBounds: CGRect
if view.layer.animation(forKey: "bounds") != nil, let presentation = view.layer.presentation() {
if (view.layer.animation(forKey: "bounds") != nil || view.layer.animation(forKey: "bounds.origin") != nil || view.layer.animation(forKey: "bounds.size") != nil), let presentation = view.layer.presentation() {
previousBounds = presentation.bounds
} else {
previousBounds = view.layer.bounds
@@ -207,6 +218,30 @@ public struct Transition {
}
}
public func setBoundsOrigin(view: UIView, origin: CGPoint, completion: ((Bool) -> Void)? = nil) {
if view.bounds.origin == origin {
completion?(true)
return
}
switch self.animation {
case .none:
view.bounds = CGRect(origin: origin, size: view.bounds.size)
view.layer.removeAnimation(forKey: "bounds")
view.layer.removeAnimation(forKey: "bounds.origin")
completion?(true)
case .curve:
let previousOrigin: CGPoint
if (view.layer.animation(forKey: "bounds") != nil || view.layer.animation(forKey: "bounds.origin") != nil), let presentation = view.layer.presentation() {
previousOrigin = presentation.bounds.origin
} else {
previousOrigin = view.layer.bounds.origin
}
view.bounds = CGRect(origin: origin, size: view.bounds.size)
self.animateBoundsOrigin(view: view, from: previousOrigin, to: origin, completion: completion)
}
}
public func setBoundsSize(view: UIView, size: CGSize, completion: ((Bool) -> Void)? = nil) {
if view.bounds.size == size {
completion?(true)