cadisplaylink

CADisplayLink and drawRect

我是研究僧i 提交于 2019-12-07 03:23:46
问题 I need help to better understand how CADisplayLink and drawRect behave, so that I can figure out how to keep my app's framerate at a smooth 60fps. My (presumably incorrect) understanding so far is the following: 1) CADisplayLink calls a specified selector when the display refreshes (a so-called "v-sync" event; about every 16ms). 2) iOS uses double buffering, meaning that while one frame buffer is being displayed we can prepare (draw to) the other, and the two are swapped at the next v-sync

How to pause a CADisplayLink?

白昼怎懂夜的黑 提交于 2019-12-06 16:38:51
I have a problem in my app. What I want to happened is when I click button2, it disappears and stops moving. What's happening now is that when I click button2, it disappears but doesn't stop moving (even while its hidden).Any help? Code: @IBOutlet var label: UILabel! @IBOutlet var label2: UILabel! @IBOutlet var label3: UILabel! @IBOutlet var button2: UIButton! @IBAction func button3(sender: UIButton) { label.hidden = false button2.hidden = true } @IBOutlet var button4: UIButton! @IBAction func button5(sender: UIButton) { button4.hidden = true label2.hidden = false } @IBAction func button1

CADisplayLink at iOS 6.0 not retaining target

落爺英雄遲暮 提交于 2019-12-05 18:36:12
I have a such code: NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(updateFrame)]]; [invocation setTarget:self]; [invocation setSelector:@selector(updateFrame)]; displayLink_ = [[CADisplayLink displayLinkWithTarget:invocation selector:@selector(invoke)] retain]; [displayLink_ setFrameInterval:1]; [displayLink_ addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; At iOS 6.0 (in 5.1 this code works ok) when this code calling I have two variants: EXC_BAD_ACCESS or 'call to unrecognized selector "invoke"'. It is

CADisplayLink and drawRect

ぃ、小莉子 提交于 2019-12-05 08:01:23
I need help to better understand how CADisplayLink and drawRect behave, so that I can figure out how to keep my app's framerate at a smooth 60fps. My (presumably incorrect) understanding so far is the following: 1) CADisplayLink calls a specified selector when the display refreshes (a so-called "v-sync" event; about every 16ms). 2) iOS uses double buffering, meaning that while one frame buffer is being displayed we can prepare (draw to) the other, and the two are swapped at the next v-sync event. 3) Therefore, from the time the display link fires, I have about 16ms to ensure that all

Use CADisplayLink as dynamic frequency timer

大憨熊 提交于 2019-12-05 03:27:12
问题 I've been using NSTimer to fade-in/fade-out some images in my app based on user-set frequency. For example, if user set frequency to 5 seconds, then every 5 seconds the following code will execute: [UIView animateWithDuration:someInterval delay:0 options:UIViewAnimationCurveEaseInOut animations: ^{ // UI alpha = ... code here } // off... completion:^(BOOL finished){ [UIView animateWithDuration:someOtherInterval delay:yetAnotherValue options:UIViewAnimationCurveEaseInOut animations: ^{ // UI

Memory usage keeps rising on older devices using Metal

徘徊边缘 提交于 2019-12-04 08:23:16
I use Metal and CADisplayLink to live filter a CIImage and render it into a MTKView . // Starting display link displayLink = CADisplayLink(target: self, selector: #selector(applyAnimatedFilter)) displayLink.preferredFramesPerSecond = 30 displayLink.add(to: .current, forMode: .default) @objc func applyAnimatedFilter() { ... metalView.image = filter.applyFilter(image: ciImage) } According to the memory monitor in Xcode, memory usage is stable on iPhone X and never goes above 100mb, on devices like iPhone 6 or iPhone 6s the memory usage keeps growing until eventually the system kills the app. I

How to correctly stop and resume a CADisplayLink?

强颜欢笑 提交于 2019-12-04 00:23:18
I figured out a big problem with CADisplayLink. I have the most basic EAGLLayer with OpenGL ES 1.1 drawing a rotating triangle for testing. This needs a run loop method to be called at screen refresh rate, so I start the runloop like this: - (void)startRunloop { if (!animating) { CADisplayLink *dl = [[UIScreen mainScreen] displayLinkWithTarget:self selector:@selector(drawFrame)]; [dl setFrameInterval:1.0]; [dl addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; self.displayLink = dl; animating = YES; } } - (void)stopRunloop { if (animating) { [self.displayLink invalidate];

Use CADisplayLink as dynamic frequency timer

落爺英雄遲暮 提交于 2019-12-03 18:15:49
I've been using NSTimer to fade-in/fade-out some images in my app based on user-set frequency. For example, if user set frequency to 5 seconds, then every 5 seconds the following code will execute: [UIView animateWithDuration:someInterval delay:0 options:UIViewAnimationCurveEaseInOut animations: ^{ // UI alpha = ... code here } // off... completion:^(BOOL finished){ [UIView animateWithDuration:someOtherInterval delay:yetAnotherValue options:UIViewAnimationCurveEaseInOut animations: ^{ // UI alpha = ... code here } completion:nil ]; } ]; (The exact code isn't important, just the overall idea of

Getting stuck at 40 fps even with using CADisplayLink?

随声附和 提交于 2019-12-03 04:49:37
At first I used NSTimer and ran into the problem of the frame rate being stuck at 40 frames per second. I've read about using CADisplayLink to fix the problem. It seemed to work for a while, but recently, the app starts at 60, then after a little while (about 5 - 20 seconds in) the app starts to run at 40 - 41 fps and gets stuck there. And I'm culling so that there's less draws when objects are out of view, but yet it stays stuck there. A unusual way that does seem to remedy the problem for a moment (about 10 seconds) is to disconnect the wire from the bottom of the iphone and then connect it

How to set CADisplayLink in Swift with weak reference between target and CADisplayLink instance

懵懂的女人 提交于 2019-12-02 01:42:31
In Objective-C, we can init CADisplayLink with Proxy Pattern to break strong reference: WeakProxy *weakProxy = [WeakProxy weakProxyForObject:self]; self.displayLink = [CADisplayLink displayLinkWithTarget:weakProxy selector:@selector(displayDidRefresh:)]; Then, just invalidate the displayLink in dealloc : - (void)dealloc { [_displayLink invalidate]; } However, NSProxy seems can't be inherited in Swift: https://bugs.swift.org/browse/SR-1715 I tried to write like this: weak var weakSelf = self displayLink = CADisplayLink(target: weakSelf!, selector: #selector(displayDidRefresh(dpLink:))) It didn