Strange UI Lag When Using CADisplayLink for Animation in Objective-C on iOS 16.1
I'm confused about I'm sure I'm missing something obvious here, but I'm experiencing a noticeable UI lag when implementing animations with `CADisplayLink` on iOS 16.1. I have a simple setup where I use `CADisplayLink` to update the position of a view based on a sine wave function for a smooth oscillation effect. However, during the animation, there seems to be a stutter or lag, especially when I have other UI elements that are also being updated frequently. I've tried optimizing the drawing code by minimizing the computational load in the `displayLink` callback but the question continues. Hereβs a simplified version of the code Iβm using: ```objective-c @interface MyViewController () { CADisplayLink *displayLink; CGFloat oscillationPhase; } @end @implementation MyViewController - (void)viewDidLoad { [super viewDidLoad]; displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateAnimation)]; [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; oscillationPhase = 0.0; } - (void)updateAnimation { oscillationPhase += 0.1; CGFloat y = 50 * sin(oscillationPhase); // Calculate new position self.animatedView.center = CGPointMake(self.animatedView.center.x, 200 + y); [self.animatedView setNeedsDisplay]; // Force redraw } @end ``` I also tried running the animation on the main queue and disabling any heavy processing during the animation, but it didn't help. I've checked the device logs and there are no important warnings or errors logged during the animation. Could the question be related to iOS 16.1's handling of the main run loop? Any insights or suggestions on how to improve the performance would be greatly appreciated! What's the best practice here? Am I missing something obvious? For context: I'm using Objective-C on Ubuntu 22.04. Thanks for your help in advance!