AppDelegate's UI Window Resizes When Modal View Is Displayed

Asked 2 years ago, Updated 2 years ago, 95 views

Now I'm creating a feature to install and take action with a view (button) that looks like when tethering.

Specifically, during certain actions, a 44px height button is placed at the top of the screen to be used as a shortcut.

The current implementation reduces the key window that AppDelegate has, creates a space at the top, and places the button there.
iOS 8 works as intended, but sometimes it doesn't work as intended with iOS 6 and 7.

The desired behavior does not occur when you display a モーmodal view 」 and when you run presentViewController: animated:completion:.
This will restore the size of the key window resized above and display a modal view over it.

As a result, the view goes under the overlapping buttons.
Do you know anything about this behavior?

[Added on February 4, 2015]

I received your comment, so I will put the minimum code to be reproduced.
Repeat the steps for

will be

-(BOOL) application:(UIAapplication*) application
didFinishLaunchingWithOptions: (NSDictionary*) launchOptions
{
    UIButton* button= [UIButtonButtonWithType: UIButtonTypeContactAdd];
    button.frame = CGRectMake(50, 150, 100, 44);
    button addTarget:self
               action:@selector(tap:)
     forControlEvents:UICControlEventTouchUpInside];


    // ViewController
    self.viewController=[[UIViewController alloc] init];
    self.viewController.view.backgroundColor=UIColor.blueColor;
    self.viewController.definesPresentationContext=NO;
    [self.viewController.viewaddSubview:button];

    UIBarButtonItem*barButton=[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                                               target —self
                                                                               action:@selector(barBtnTap:);
    self.viewController.navigationItem.rightBarButtonItem=barButton;


    // NavigationController
    UINavigationController*nv = [[UINavigationController alloc] initWithRootViewController:self.viewController];

    self.window=[UIWindow alloc] initWithFrame: UISscreen.mainScreen.bounds];
    self.window.backgroundColor=UIColor.redColor;
    self.window.rootViewController=nv;
    self.window makeKeyAndVisible;

    return YES;
}

- (void)barBtnTap: (id)sender
{
    UIView* mark = [[UIView alloc] initWithFrame: CGRectMake(0,0,50,50)];
    mark.backgroundColor=UIColor.yellowColor;
    UIViewController* modal=[UIViewController alloc] init];
    modal.view.backgroundColor=UIColor.grayColor;
    modal.view addSubview:mark;
    [self.viewController presentViewController:modal]
                                      animated —YES
                                    completion:nil];
}

- (void)tap: (id)sender
{
    self.backupFrame =self.window.frame;
    CGRect newFrame =self.window.frame;

    NSInteger pad = 60;
    newFrame.size.height-=pad;
    newFrame.origin.y+=pad;

    self.window.frame = newFrame;

    CGRect otherFrame = CGRectMake(0,0, newFrame.size.width, pad);
    self.otherWindow=[UIWindow alloc] initWithFrame: otherFrame];
    self.otherWindow.backgroundColor=UIColor.greenColor;
    [self.otherWindow makeKeyAndVisible];
}

ios objective-c iphone ios6

2022-09-30 19:22

1 Answers

The view(00;320480) created in loadView of UIViewController that I checked and found was view(0-60;320480) when viewWillLayoutSubviews was called.
Therefore, after implementing it as follows, we have confirmed that it works as expected.

 - (void) viewWillLayoutSubviews
{
    // [UIAApplication sharedApplication].keyWindow so that you can get the desired window
    // self.otherWindow makeKeyAndVisible; after
    // self.window makeKeyWindow; doing so.
    CGSize windowSize = [UIApplication sharedApplication].keyWindow.frame.size;
    self.view.frame = CGRectMake(0,0, windowSize.width, windowSize.height);
    superviewWillLayoutSubviews;
}

Because you don't know the details of when the view.frame changes, a different location may be appropriate instead of viewWillLayoutSubviews.


2022-09-30 19:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.