Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you add a view of another view controller as a subview to the active window of the application you must synchronize its <code>center</code>, <code>bounds</code> and <code>transform</code> properties with <code>window.rootViewController.view</code>. Also be sure your top view is added <strong>after</strong> correct initialization of the window, and also <strong>after</strong> its root subview has been added to it as a subview.</p> <p>I suppose this can be done in multiple ways, I've made it work through use of <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html" rel="nofollow">Key-value observing</a>.</p> <p>Here the <code>topViewController</code> is instance of a <code>UIViewController</code> subclass and it represents the view controller of the <code>UIView</code> that should be on top of the application window</p> <p><code>AppDelegate.m</code>:</p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self.window.rootViewController.view addObserver:topViewController forKeyPath:@"transform" options:NSKeyValueObservingOptionNew context:@"rootView"]; [self.window.rootViewController.view addObserver:topViewController forKeyPath:@"center" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:@"rootView"]; [self.window.rootViewController.view addObserver:topViewController forKeyPath:@"bounds" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:@"rootView"]; return YES; } </code></pre> <p><code>topViewController</code>'s <code>.m</code> file:</p> <pre><code>-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if([(__bridge_transfer NSString*)context isEqualToString:@"rootView"]) { if([keyPath isEqualToString:@"transform"]) { self.view.transform = [[change objectForKey:NSKeyValueChangeNewKey] CGAffineTransformValue]; } else if ([keyPath isEqualToString:@"center"]) { self.view.center = [[change objectForKey:NSKeyValueChangeNewKey] CGPointValue]; } else if ([keyPath isEqualToString:@"bounds"]) { self.view.bounds = [[change objectForKey:NSKeyValueChangeNewKey] CGRectValue]; } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload