iOS Developer Library — Pre-Release

Developer

GLKit Framework Reference GLKViewController Class Reference

Options
Deployment Target:

On This Page
Language:

GLKViewController

The GLKViewController class provides all of the standard view controller functionality, but additionally implements an OpenGL ES rendering loop. A GLKViewController object works in conjunction with a GLKView object to display frames of animation in the view.

To use this class, allocate and initialize a new GLKViewController subclass and set its view property to point to a GLKView object. Then, configure the view controller’s preferredFramesPerSecond property to the desired frame rate your application requires. You can set a delegate or configure other properties on the view controller, such as whether the animation loop is automatically paused or resumed when the application moves into the background.

When active, rendering loop automatically updates the view’s contents each time a new frame must be displayed. Each frame is rendered by the view controller using these steps:

  1. The view controller calls its delegate’s glkViewControllerUpdate: method. Your delegate should update frame data that does not involve rendering the results to the screen.

  2. The view controller calls its view’s display method. Your view should redraw the frame.

Subclassing Notes

Your application should subclass GLKViewController and override the viewDidLoad and viewDidUnload methods. Your viewDidLoad method should set up your context and any drawable properties and can perform other resource allocation and initialization. Similarly, your class’s viewDidUnload method should delete the drawable object and free any unneeded resources.

As an alternative to implementing a glkViewControllerUpdate: method in a delegate, your subclass can provide an update method instead. The method must have the following signature:

  • - (void)update;

Inheritance


Import Statement


Swift

import GLKit

Objective-C

@import GLKit;

Availability


Available in iOS 5.0 and later.
  • The rate you want the view controller to call the view to update the contents of the view.

    Declaration

    Swift

    var preferredFramesPerSecond: Int

    Objective-C

    @property(nonatomic) NSInteger preferredFramesPerSecond

    Discussion

    When your application sets its preferred frame rate, the view controller chooses a frame rate as close to that as possible based on the capabilities of the screen the view is displayed on. The actual frame rate chosen is usually a factor of the maximum refresh rate of the screen to provide a consistent frame rate. For example, if the maximum refresh rate of the screen is 60 frames per second, that is also the highest frame rate the view controller sets as the actual frame rate. However, if you ask for a lower frame rate, it might choose 30, 20, 15 or some other factor to be the actual frame rate.

    Your application should choose a frame rate that it can consistently maintain.

    The default value is 30 frames per second.

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in iOS 5.0 and later.

    See Also

    framesPerSecond

  • The actual rate that the view controller attempts to call the view to update its contents. (read-only)

    Declaration

    Swift

    var framesPerSecond: Int { get }

    Objective-C

    @property(nonatomic, readonly) NSInteger framesPerSecond

    Discussion

    The view controller attempts to maintain this frame rate, but it may still drop frames if the per-frame processing performed by your application takes more time than the time between frames.

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in iOS 5.0 and later.

  • delegate delegate Property

    The view controller’s delegate.

    Declaration

    Swift

    @IBOutlet unowned(unsafe) var delegate: GLKViewControllerDelegate!

    Objective-C

    @property(nonatomic, assign) IBOutlet id<GLKViewControllerDelegate> delegate

    Discussion

    The delegate is optional.

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in iOS 5.0 and later.

  • paused paused Property

    A Boolean value that indicates whether the rendering loop is paused.

    Declaration

    Swift

    var paused: Bool

    Objective-C

    @property(nonatomic, getter=isPaused) BOOL paused

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in iOS 5.0 and later.

  • A Boolean value that indicates whether the view controller automatically pauses the rendering loop when the application resigns the active state.

    Declaration

    Swift

    var pauseOnWillResignActive: Bool

    Objective-C

    @property(nonatomic) BOOL pauseOnWillResignActive

    Discussion

    The default value is YEStrue. If your application sets this to NOfalse, it must explicitly set the paused property to YEStrue when the application resigns the active state.

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in iOS 5.0 and later.

  • A Boolean value that indicates whether the view controller automatically resumes the rendering loop when the application becomes active.

    Declaration

    Swift

    var resumeOnDidBecomeActive: Bool

    Objective-C

    @property(nonatomic) BOOL resumeOnDidBecomeActive

    Discussion

    The default value is YEStrue. If your application sets this to NOfalse, it must explicitly set the paused property to NOfalse when the application becomes active.

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in iOS 5.0 and later.

  • The number of frame updates that have been sent by the view controller since it was created. (read-only)

    Declaration

    Swift

    var framesDisplayed: Int { get }

    Objective-C

    @property(nonatomic, readonly) NSInteger framesDisplayed

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in iOS 5.0 and later.

  • The amount of time that has passed since first time the view controller resumed sending update events. (read-only)

    Declaration

    Swift

    var timeSinceFirstResume: NSTimeInterval { get }

    Objective-C

    @property(nonatomic, readonly) NSTimeInterval timeSinceFirstResume

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in iOS 5.0 and later.

  • The amount of time that has passed since the last time the view controller resumed sending update events. (read-only)

    Declaration

    Swift

    var timeSinceLastResume: NSTimeInterval { get }

    Objective-C

    @property(nonatomic, readonly) NSTimeInterval timeSinceLastResume

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in iOS 5.0 and later.

  • The amount of time that has passed since the last time the view controller called the delegate’s glkViewControllerUpdate: method. (read-only)

    Declaration

    Swift

    var timeSinceLastUpdate: NSTimeInterval { get }

    Objective-C

    @property(nonatomic, readonly) NSTimeInterval timeSinceLastUpdate

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in iOS 5.0 and later.

  • The amount of time that has passed since the last time the view controller called the view’s display method. (read-only)

    Declaration

    Swift

    var timeSinceLastDraw: NSTimeInterval { get }

    Objective-C

    @property(nonatomic, readonly) NSTimeInterval timeSinceLastDraw

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in iOS 5.0 and later.