How to make "actionSheet showFromRect" in iOS 8?

In iOS 7, I show an ActionSheet using the showFromRect function:

[actionSheet showFromRect:rect inView:view animated:YES];

But in iOS 8, this does not work. They replace the implementation and offer us to use the UIAlertController. Then, how to show this ActionSheet as a popover?

+3
source share
4 answers

I found out that the point is in iOS 7, you show actionSheetin a new window when using "showFromRect: inView:";

But in iOS 8, you actionSheetonly show in the view that you send in the options.

So the solution is to send

self.superView
    [actionSheet showFromRect:rect inView:[self.superView] animated:YES];

My colleague and I figured it out randomly.

-1
source

UIAlertController popoverPresentationController, sourceView (aka inView) sourceRect (aka fromRect). , showFromRect: inView:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleActionSheet];

// Set the sourceView.
alert.popoverPresentationController.sourceView = self.mySubView;

// Set the sourceRect.
alert.popoverPresentationController.sourceRect = CGRectMake(50, 50, 10, 10);

// Create and add an Action.
UIAlertAction *anAction = [UIAlertAction actionWithTitle:@"Action Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
NSLog(@"Action Pressed");
}];

[alert addAction:anAction];

// Show the Alert.
[self presentViewController:alert animated:YES completion:nil];
+9

, , UIActionSheet UIWindow.view iPad-, UIWindow rootViewController.

, , UIActionSheet , rootViewController nil, UIActionSheet .

-

window.rootViewController = [[UIViewController alloc] init];

[actionSheet showFromRect:rect inView:window.rootViewController.view animated:YES].

, !

+3

Source: https://habr.com/ru/post/1545660/


All Articles