iOS Developer Library

Developer

UIKit Framework Reference UIWindow Class Reference

Options
Deployment Target:

On This Page
Language:

UIWindow

Inheritance


Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later.

The UIWindow class defines an object known as a window that manages and coordinates the views an app displays on a device screen. Unless an app can display content on an external device screen, an app has only one window.

The two principal functions of a window are to provide an area for displaying its views and to distribute events to the views. To change the content your app displays, you can change the window’s root view; you don’t create a new window. A window belongs to a level—typically, UIWindowLevelNormal—that represents where it sits on the z-axis relative to other windows. For example, a system alert window appears above normal app windows.

For more information about how to use windows, see Multiple Display Programming Guide for iOS.

  • The receiver’s window level.

    Declaration

    Swift

    var windowLevel: UIWindowLevel

    Objective-C

    @property(nonatomic) UIWindowLevel windowLevel

    Discussion

    Levels are ordered so that each level groups windows within it in front of those in all preceding groups. For example, alert windows appear in front of all normal-level windows. When a window enters a new level, it’s ordered in front of all its peers in that level. See UIWindowLevel for a list of possible values. The default value is 0.0.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • screen screen Property

    The screen on which the window is currently displayed.

    Declaration

    Swift

    var screen: UIScreen

    Objective-C

    @property(nonatomic, retain) UIScreen *screen

    Discussion

    By default, all windows are created on the primary device screen. If additional screens are attached to the device, assigning a different screen object to this property causes the window to be displayed on the new screen.

    Moving windows from screen to screen is a relatively expensive operation and should not be done in performance-sensitive code. Instead, it’s recommended that you change the screen before displaying the window the first time. Changing the screen of a window that has not yet been ordered onto the screen has no significant additional cost.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • The root view controller for the window.

    Declaration

    Swift

    var rootViewController: UIViewController?

    Objective-C

    @property(nonatomic, retain) UIViewController *rootViewController

    Discussion

    The root view controller provides the content view of the window. Assigning a view controller to this property (either programmatically or using Interface Builder) installs the view controller’s view as the content view of the window. If the window has an existing view hierarchy, the old views are removed before the new ones are installed.

    The default value of this property is nil.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

  • Converts a point from the receiver’s coordinate system to that of another window.

    Declaration

    Swift

    func convertPoint(_ point: CGPoint, toWindow window: UIWindow?) -> CGPoint

    Objective-C

    - (CGPoint)convertPoint:(CGPoint)point toWindow:(UIWindow *)window

    Parameters

    point

    A point specifying a location in the logical coordinate system of the receiver.

    window

    The window into whose coordinate system point is to be converted. If nil, this method converts the point to the logical coordinate system of the screen, which is measured in points.

    Return Value

    The point converted to the coordinate system of window.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Converts a point from the coordinate system of a given window to that of the receiver.

    Declaration

    Swift

    func convertPoint(_ point: CGPoint, fromWindow window: UIWindow?) -> CGPoint

    Objective-C

    - (CGPoint)convertPoint:(CGPoint)point fromWindow:(UIWindow *)window

    Parameters

    point

    A point specifying a location in the coordinate system of window.

    window

    The window with point in its coordinate system. If nil, this method converts the point from the logical coordinate system of the screen, which is measured in points.

    Return Value

    The point converted to the coordinate system of the receiver.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Converts a rectangle from the receiver’s coordinate system to that of another window.

    Declaration

    Swift

    func convertRect(_ rect: CGRect, toWindow window: UIWindow?) -> CGRect

    Objective-C

    - (CGRect)convertRect:(CGRect)rect toWindow:(UIWindow *)window

    Parameters

    rect

    A rectangle in the receiver's coordinate system.

    window

    The window that is the target of the conversion operation. If nil, this method instead converts the rectangle to the logical coordinate system of the screen, which is measured in points.

    Return Value

    The converted rectangle.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Converts a rectangle from the coordinate system of another window to that of the receiver.

    Declaration

    Swift

    func convertRect(_ rect: CGRect, fromWindow window: UIWindow?) -> CGRect

    Objective-C

    - (CGRect)convertRect:(CGRect)rect fromWindow:(UIWindow *)window

    Parameters

    rect

    The rectangle in the window's coordinate system.

    window

    The window with rect in its coordinate system. If nil, this method instead converts the rectangle from the logical coordinate system of the screen, which is measured in points.

    Return Value

    The converted rectangle.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Dispatches events sent to the receiver by the UIApplication object to its views.

    Declaration

    Swift

    func sendEvent(_ event: UIEvent)

    Objective-C

    - (void)sendEvent:(UIEvent *)event

    Parameters

    event

    The event to process.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The positioning of windows relative to each other.

    Declaration

    Swift

    typealias UIWindowLevel = CGFloat

    Objective-C

    const UIWindowLevel UIWindowLevelNormal; const UIWindowLevel UIWindowLevelAlert; const UIWindowLevel UIWindowLevelStatusBar; typedef CGFloat UIWindowLevel;

    Constants

    • UIWindowLevelNormal

      UIWindowLevelNormal

      The default level.

      Available in iOS 2.0 and later.

    • UIWindowLevelAlert

      UIWindowLevelAlert

      The level for an alert view.

      Available in iOS 2.0 and later.

    • UIWindowLevelStatusBar

      UIWindowLevelStatusBar

      The level for a status window.

      Available in iOS 2.0 and later.

    Discussion

    The stacking of levels takes precedence over the stacking of windows within each level. That is, even the bottom window in a level obscures the top window of the next level down. Levels are listed in order from lowest to highest.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Keys used to get values from the user information dictionary of keyboard notifications.

    Declaration

    Swift

    let UIKeyboardFrameBeginUserInfoKey: String let UIKeyboardFrameEndUserInfoKey: String let UIKeyboardAnimationCurveUserInfoKey: String let UIKeyboardAnimationDurationUserInfoKey: String

    Objective-C

    NSString *const UIKeyboardFrameBeginUserInfoKey; NSString *const UIKeyboardFrameEndUserInfoKey; NSString *const UIKeyboardAnimationDurationUserInfoKey; NSString *const UIKeyboardAnimationCurveUserInfoKey; // Deprecated in iOS 3.2 and later. NSString *const UIKeyboardCenterBeginUserInfoKey; NSString *const UIKeyboardCenterEndUserInfoKey; NSString *const UIKeyboardBoundsUserInfoKey;

    Constants

    • UIKeyboardFrameBeginUserInfoKey

      UIKeyboardFrameBeginUserInfoKey

      The key for an NSValue object containing a CGRect that identifies the start frame of the keyboard in screen coordinates. These coordinates do not take into account any rotation factors applied to the window’s contents as a result of interface orientation changes. Thus, you may need to convert the rectangle to window coordinates (using the convertRect:fromWindow: method) or to view coordinates (using the convertRect:fromView: method) before using it.

      Available in iOS 3.2 and later.

    • UIKeyboardFrameEndUserInfoKey

      UIKeyboardFrameEndUserInfoKey

      The key for an NSValue object containing a CGRect that identifies the end frame of the keyboard in screen coordinates. These coordinates do not take into account any rotation factors applied to the window’s contents as a result of interface orientation changes. Thus, you may need to convert the rectangle to window coordinates (using the convertRect:fromWindow: method) or to view coordinates (using the convertRect:fromView: method) before using it.

      Available in iOS 3.2 and later.

    • UIKeyboardAnimationCurveUserInfoKey

      UIKeyboardAnimationCurveUserInfoKey

      The key for an NSNumber object containing a UIViewAnimationCurve constant that defines how the keyboard will be animated onto or off the screen.

      Available in iOS 3.0 and later.

    • UIKeyboardAnimationDurationUserInfoKey

      UIKeyboardAnimationDurationUserInfoKey

      The key for an NSNumber object containing a double that identifies the duration of the animation in seconds.

      Available in iOS 3.0 and later.

    • UIKeyboardCenterBeginUserInfoKey

      UIKeyboardCenterBeginUserInfoKey

      The key for an NSValue object containing a CGPoint that is the center of the keyboard in window coordinates before animation. These coordinates actually take into account any rotation factors applied to the window’s contents as a result of interface orientation changes. Thus, the center point of the keyboard is different in portrait versus landscape orientations.

      Use the UIKeyboardFrameBeginUserInfoKey key instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 3.2.

    • UIKeyboardCenterEndUserInfoKey

      UIKeyboardCenterEndUserInfoKey

      The key for an NSValue object containing a CGPoint that is the center of the keyboard in window coordinates after animation. These coordinates take into account any rotation factors applied to the window’s contents as a result of interface orientation changes. Thus, the center point of the keyboard is different in portrait versus landscape orientations.

      Use the UIKeyboardFrameEndUserInfoKey key instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 3.2.

    • UIKeyboardBoundsUserInfoKey

      UIKeyboardBoundsUserInfoKey

      The key for an NSValue object containing a CGRect that identifies the bounds rectangle of the keyboard in window coordinates. This value is sufficient for obtaining the size of the keyboard. If you want to get the origin of the keyboard on the screen (before or after animation) use the values obtained from the user info dictionary through the UIKeyboardCenterBeginUserInfoKey or UIKeyboardCenterEndUserInfoKey constants.

      Use the UIKeyboardFrameBeginUserInfoKey or UIKeyboardFrameEndUserInfoKey key instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 3.2.