半透明modalViewController

问题描述 投票:1回答:2

我一直在研究这个,似乎唯一的方法是使用UIActionSheet,问题是我的UIActionSheet只覆盖了屏幕的一半,我的代码是:

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];

另外,我如何从我的MyViewController中删除这个UIActionSheet?有没有比这更好的解决方案?这是我加载一半屏幕的意思截图:

screenshot

这是a sample project来说明我的问题。

ios objective-c iphone ipad uiactionsheet
2个回答
1
投票

UIActionSheet将根据其中的UIButtons数量增加或减少它的高度。您可以做的是在视图上方添加另一个视图,并添加所需的alpha。并将其从子视图中删除,并根据您的要求添加子视图,即在显示动作表时添加子视图,并在解除UIActionSheet时删除。我希望这与您的问题相关,它将帮助您解决问题。


1
投票

问题是因为TestViewController的框架大小和添加UIView作为UIActionSheet的子视图的方法。

进行以下更改,并且正确解雇!

用这种方法实现willPresentActionSheetaddSubView

- (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];

}

viewDidLoadTestViewController中,设置

- (void)viewDidLoad
{
self.view.frame = CGRectMake(0,0 , 320, 60);
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
© www.soinside.com 2019 - 2024. All rights reserved.