How to display UIActionSheet just below top navigation status bar on iPhone
Asked Answered
T

2

6

I would like to display an action sheet sliding from just below the very top status bar.

When I use the navigationBar as the view to show in, the sheet is still displayed at the bottom of the screen. How can I show it originating from the top instead?

The class I'm calling the following code from is a 'UIViewController'

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Hello" delegate:nil 
          cancelButtonTitle:nil 
          destructiveButtonTitle:nil 
          otherButtonTitles:nil];

UINavigationBar *navBar = self.navigationController.navigationBar;

[sheet showInView:navBar];

I've seen some apps show a sliding out drawer of some sort from where the status bar is.(eg: Twitterrific) How is this done?

Tompion answered 14/1, 2010 at 18:36 Comment(0)
D
4

Apple has stated that they simply would like all action sheets to work the same way and slide in from the same direction. Hence there is no advertised way to easily manipulate their animations and such.

Dryer answered 14/1, 2010 at 19:17 Comment(3)
What about location though? The action sheet not only animates from the bottom of a view, it seems to always animate from the bottom of the screen.Cf
Not always: with a tab bar, it shows from above it, unless you showInView: on the outer window.Momently
I thought by using the navigation bar which is placed at the top (and also inherits from UIView), I'd be able to make it slide from the top. But no it doesn't work that way.Tompion
D
0

Sure it is possible. Not really easy but it is. Do it like this:

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle...];
sheet.transform = CGAffineTransformmakeRotation(M_PI);
[sheet showInView:view];

The view in which it is presented (here called view) should also be transformed. Do also:

view.transform = CGAffineTransformMakeRotation(M_PI);

Use for example an empty view, which just has the job to present this ActionSheet.

I hope it was understanable.^^

Sandro Meier

Doran answered 30/1, 2010 at 16:5 Comment(1)
This reverses both the sheet and the view; but if the view contains things, they will show upside down.Lepsy

© 2022 - 2024 — McMap. All rights reserved.