iphone - UIApplication sharedApplication - keyWindow is nil? -
I want to change a CGPoint to sync with my UIVU UI window and realize that UIApplication keyWindow is always is null; Why is it like this?
I have tried to convert: toView:
method in UIView
Please see the template of a Xcode (View Application) in View Controller, to view this sample code:
- (zero) viewDidoadload {[Super stuffed]; UIView * test = [[UIView alloc] initWithFrame: CGRectMake (40,40,250,250)]; [Test setback color: [UIColor redColor]]; [Self.view addSubview: test]; CGPoint p = CGPointMake (100, 100); CGPoint NP; NP = [Convert Points: P. toView: [[UIPP Application Shared Application] Keywindow]]; NSLog (@ "P:% @ NP:% @", NSSTINGFROMCCP (P), NSSTINGFROMCPNT (NP)); AppDelegate * appDel = (AppDelegate *) [UIApplication ShareApp] .delegate; NP = [Convert point: P toview: [app del window]]; NSLog (@ "P:% @ NP:% @", NSSTINGFROMCCP (P), NSSTINGFROMCPNT (NP)); NP = [Convert Points: P to View: Nile]; NSLog (@ "P:% @ NP:% @", NSSTINGFROMCCP (P), NSSTINGFROMCPNT (NP)); [Test release]; If (! [UIApplication shared application] key window]] NSLog (@ "Window was zero"); }
And I get:
p: {100, 100} NP: {100, 100} p: {100, 100} NP: {140, 160} P: {100, 100} NP: {100, 100} The window was zero
I can change it but only when I reach the window through app representative Reaches And not according to the UIApplication documentation, the main window should work here, but it is zero. Why is it like this?
The easiest way is to get the window from the app representative:
UIWindow * keyWindow = [[[UIApplication shared application] Rep] window]; // Now do something from the window
Comments
Post a Comment