Instance Method

addPresentedHandler:

Registers a block of code to be called immediately after the drawable is presented.

Required.

Declaration

- (void)addPresentedHandler:(MTLDrawablePresentedHandler)block;

Parameters

block

A block of code to be invoked.

Discussion

You can register multiple handlers for a single drawable object.

The following example code schedules a presentation handler that reads the presentedTime property and uses it to derive the interval between the last and current presentation times. From that information, it determines the app’s frame rate.

// Property declarations
@property (nonatomic) CFTimeInterval previousPresentedTime;
/* ... */
// Render loop
__block Renderer *strongSelf = self;
[view.currentDrawable addPresentedHandler:^(id<MTLDrawable> drawable) {
    CFTimeInterval presentationDuration = drawable.presentedTime - strongSelf.previousPresentedTime;
    CFTimeInterval frameRate = 1.0/presentationDuration;
    /* ... */
    strongSelf.previousPresentedTime = drawable.presentedTime;
}];

See Also

Getting Presentation Information

MTLDrawablePresentedHandler

A block of code invoked after a drawable is presented.

presentedTime

The host time, in seconds, when the drawable was displayed onscreen.

Required.