meds
meds

Reputation: 22956

At what framerate does the iOS UI run animations at?

I've been trying to figure this out, people say 60fps but there is no solid evidence to this as far as I can tell?

Upvotes: 0

Views: 5643

Answers (4)

Bohm
Bohm

Reputation: 1004

How about setting the output function in the view controller?:

 spriteView.showsFPS = YES;

Are we implying that the output value is not reliable?

Upvotes: -1

Rob
Rob

Reputation: 438047

You can create a display link (CADisplayLink) which will be called as the screen is updated.

Create some properties to keep track of the display link and variables to calculate the frame rate:

@property (nonatomic, strong) CADisplayLink *displayLink;
@property (nonatomic) CFTimeInterval startTime;
@property (nonatomic) NSInteger frameCount;

And you can then have methods to start, stop, and handle the display link:

- (void)startDisplayLink
{
    self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(handleDisplayLink:)];
    self.startTime = CACurrentMediaTime();
    [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}

- (void)stopDisplayLink
{
    [self.displayLink invalidate];
    self.displayLink = nil;
}

// This handler will update a label on the screen with the frame rate once per second

- (void)handleDisplayLink:(CADisplayLink *)displayLink
{
    self.frameCount++;

    CFTimeInterval now = CACurrentMediaTime();
    CFTimeInterval elapsed = now - self.startTime;

    if (elapsed >= 1.0) {
        CGFloat frameRate = self.frameCount / elapsed;

        // either, like below, update a label that you've added to the view or just log the rate to the console

        self.frameRateLabel.text = [NSString stringWithFormat:@"%.1f", frameRate];

        self.frameCount = 0;
        self.startTime = now;
    }
}

Then just start the display link (call startDisplayLink) and the above handler will report the calculated rate.

I personally prefer this to Instruments, because I find that Instruments itself impacts the performance more than the above code will (with Instruments your frame rates can appear lower than they really are). Clearly, this above code will also impact performance, but it's modest. Also, the above lets you measure the performance on a device untethered from your computer: You always should measure performance on a physical device rather than the simulator.

In answer to the question regarding the achieved frame rate, the above will illustrate that in simple animations, a frame rate of 60 fps is generally achieved, but the more complicated/numerous the animations are, the lower the achieved rate will be.

Upvotes: 4

jbutler483
jbutler483

Reputation: 24559

Found this here:http://answers.unity3d.com/questions/32841/is-it-possible-to-get-above-30-fps-on-an-ios-devic.html

Yes- when you compile to xcode, look in the AppController.mm- there's a variable kFPS.

Set this to, say 60.

It's good practice I think to set it as high, so you have room to lower the cap.

Thereafter, be aware that 60fps games eat batteries for breakfast :)

Upvotes: 0

Droppy
Droppy

Reputation: 9731

Use Instruments to find out yourself, as it will depend on the app.

Upvotes: 2

Related Questions