Zer0
Zer0
TSDThe Swift Den
Created by Zer0 on 3/12/2024 in #swift-development
Am I trippin' or is this animation absolutely not behaving like intended ?
I was trying to fix some animation problem and somehow got down to this weird behavior :
import SwiftUI

struct ContentView: View {
@State private var yPos: Double = 0 // Start with no offset

var body: some View {

HoldCue()
.position(x: 100, y: yPos )
.animation(Animation.linear(duration: 1), value: yPos)
.onAppear {
yPos = 200
}

}
}

struct HoldCue: View {
@State private var size: Double = 20

var body: some View {
ZStack {
Circle()
.frame(width: size, height: size)
.animation(Animation.linear(duration: 1).repeatForever(autoreverses: true), value: size)
.onAppear {
// Start the pulsing animation independently
size = 50
}
}
}
}



#Preview {
ContentView()
}
import SwiftUI

struct ContentView: View {
@State private var yPos: Double = 0 // Start with no offset

var body: some View {

HoldCue()
.position(x: 100, y: yPos )
.animation(Animation.linear(duration: 1), value: yPos)
.onAppear {
yPos = 200
}

}
}

struct HoldCue: View {
@State private var size: Double = 20

var body: some View {
ZStack {
Circle()
.frame(width: size, height: size)
.animation(Animation.linear(duration: 1).repeatForever(autoreverses: true), value: size)
.onAppear {
// Start the pulsing animation independently
size = 50
}
}
}
}



#Preview {
ContentView()
}
I'm probably too tired and missed something obvious but I can't figure why the position animation keeps repeating even though it's not set as repeatForever. I've used the animation(Animation, Value) modifier that is supposed to limit context merge. Try it out and tell me if you get the same result!
4 replies
TSDThe Swift Den
Created by Zer0 on 7/14/2023 in #swift-development
I'm having a stroke with CGEvents and simulated input - please help
Anyone here happened to mess with the Quartz Event Services API ? I'm having a hard time trying to simulate input to a particular app. My goal is to achieve a simulated click input at any coordinates in a target app's window, if possible even if it is in the background (not foremost). The purpose of this is to have an automated custom routine running on an app in the background without hindering mouse movements and clicks. Apparently the Quartz Event Services API is the best option for that. Using CGEvent().post() works pretty well, but since I'm trying to target a particular app, i'd prefer to use CGEvent().postToPID(). Also CGEvent().post moves the mouse to the click's position, making it unfit for my problem. The problem is, the postToPID method doesn't work correctly ( or doesn't seem to at least). Any CGEvent mouse click posted with it only works if its coordinates are over the menu bar. Unfortunately, the postToPID method doesn't have any documentation, which makes doubtful about if it even is supposed to work. I also did a bunch of shenanigans trying to make it work : - tried using NSEvent : *not working *- it seems you can't send an NSEvent to an external app - tried using AppleScript : not working on 3rd party apps with an incompatible ui - tried listening to the events posted by post() and replicating their values manually : not working - even using the exact same event configuration and mouse event types with postToPID did not trigger a mouse click - tried listening to the events generated by an actual mouse click and programmatically replicating them (using CGEvent.copy()) : did not work - tried moving the mouse at the exact coordinates as the click - maybe the mouse had to be at the same point to work ( even though postToPID works on the menu bar without the mouse at the same spot) : did not work If you have any idea or solution I'd by happy to hear it! I've already spent 30+ hours on it, won't stop 'till I'm sure its not possible.
1 replies