半透明modalViewController

发布于 2024-11-28 02:49:21 字数 938 浏览 1 评论 0 原文

我一直在研究这个,似乎唯一的方法是使用 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?还有比这更好的解决方案吗?这是我所说的加载一半屏幕的屏幕截图:

屏幕截图

这里是 示例项目来说明我的问题。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戏舞 2024-12-05 02:49:21

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

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.

谁许谁一生繁华 2024-12-05 02:49:21

问题是由于 TestViewController 的框架大小以及将 UIView 添加为 UIActionSheet 的子视图的方法造成的。

进行以下更改,即可正确关闭!

在该方法中实现 willPresentActionSheet 和 addSubView

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

}

并在 TestViewController 的 viewDidLoad 中设置

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

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.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文