ViewController do zoom in behind a UIAlertController

Hello everyone, I'm not sure how to ask my question?

When my UIAlertController appears, my ViewController in the background zoom (grows)?

I use the code below in objective-c Xcode 11.3.1:

I can't figure it out why ? I would apreciate if someone can make me on the way.


- (void)productDescription:(NSInteger)index {
    SKProduct *product = _products[index];


    UIAlertController *alert = [UIAlertController alertControllerWithTitle:product.localizedTitle
                                                                   message:product.localizedDescription
                                                            preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(kOK,@"") style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * action) {
                                                         [self buyProduct:index];
                                                     }
                               ];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(kCANCEL,@"") style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action) {
                                                         }
                                   ];
    [alert addAction:okAction];
    [alert addAction:cancelAction];
    
    UIViewController *topController = self.window.rootViewController;
    while (topController.presentedViewController) topController = topController.presentedViewController;
    
    [topController presentViewController:alert animated:YES completion:nil];


}
Here is the link to view the effect https://www.judogokyo.com/ftp/iPad_badZoom.mp4

Could youn explain what you are trying by searching for the top controller ?


I read in doc about rootViewController:

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

I looked in detail at video, it seems that only the alert window changes size.


Why not just present on self ?

[self presentViewController:alertController animated:YES completion:nil];


Or try setting animated to NO

DonaldLaborde - I have no idea why your viewController is enlarging, sorry.


Claude31 - The issue is that you need to present a viewController only from the top most viewController. The rootViewController might not be the top most viewController - it (and any viewController it presents) may be presenting another viewController. This finds that top most viewController:

UIViewController *topController = self.window.rootViewController;

    while (topController.presentedViewController) topController = topController.presentedViewController; 

In your case, the zoom is on the alert view, not on the background view.


I have an impression, but difficult to be affirmative.

I looked at how an alert appear. Seems that there is a very slight zoom effect when the alert appears, but so fast that we do not notice.


In your case, could it be that the delay to search for the controller delays this transition, making it noticeable.

Longshot answer......


The response in productsRequest is off the main queue. You need to get back to the main queue otherwise you get an error message (did you?) and your responses will be delayed until the main queue is re-entered (or something - I don't fully understand queues). This is new behavior for productsRequest - it used to get called on tghe main queue. So add this:



-(void) productsRequest: (SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
    
    dispatch_async(dispatch_get_main_queue(), ^{

        //     the code that used to be in productsRequest goes here.  Add "self->" to global variables

    });
ViewController do zoom in behind a UIAlertController
 
 
Q