aherlambang
aherlambang

Reputation: 14418

semi transparent modalViewController

I've been researching this and it seems that the only way to do this is using UIActionSheet, the question is that my UIActionSheet only covers half of the screen, my code is:

MyViewController *myVC = [[myViewController alloc] init];
UIActionSheet *myActionSheet = [[UIActionSheet alloc] initWithTitle:@"\n\n"
                                                           delegate:self
                                                  cancelButtonTitle:@"cancel"
                                             destructiveButtonTitle:@"done"
                                                  otherButtonTitles:nil];
[myActionSheet addSubview:myVC.view];
[myActionSheet showInView:currentView];
[myActionSheet release];

Also how do I then dismiss this UIActionSheet from my MyViewController? Is there any better solution than this? Here's a screenshot of what I mean by loading half of the screen:

screenshot

Here's a sample project to illustrate my issue.

Upvotes: 1

Views: 161

Answers (2)

Baby Groot
Baby Groot

Reputation: 4279

UIActionSheet will increase or decrease it's height according to the number of UIButtons in it. What you can do is add another view above your view with your desired alpha. And remove it from subview and add in subview according to your requirement i.e. add subview when you are displaying actionsheet and remove when you are dismissing UIActionSheet. I hope this is relevant to your question and it will help you to solve your problem.

Upvotes: 1

Legolas
Legolas

Reputation: 12345

The problem is because of the frame size of your TestViewController and method for adding the UIView as a subView of the UIActionSheet.

Make the following changes, and it is dismissing properly !

Implement willPresentActionSheet and addSubView in that method

- (IBAction)pressed:(id)sender
{
UIActionSheet *myActionSheet = [[UIActionSheet alloc] initWithTitle:@"\n\n" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"done" otherButtonTitles:nil];
[myActionSheet showInView:self.view];
[myActionSheet release];   
}


- (void) willPresentActionSheet:(UIActionSheet *)actionSheet{

TestViewController *myVC = [[TestViewController alloc] init];
[actionSheet addSubview:myVC.view];

}

And in the viewDidLoad of the TestViewController, set

- (void)viewDidLoad
{
self.view.frame = CGRectMake(0,0 , 320, 60);
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}

Upvotes: 1

Related Questions