我正在尝试做一些不应该那么复杂的事情,但我无法弄清楚。 我有一个 UIViewController 显示 UITableView。我想当用户按一行时显示一个上下文菜单。我希望这是一个带有标签和按钮的半透明 View 。 我可以使用 AlertView,但我希望完全控制标签和按钮的格式,并且希望使用 Interface Builder。
因此,我创建了 250x290 的小 View ,将 alpha 设置为 0.75,并创建一个带有 socket 的 View Controller 来处理不同的用户事件。
现在我想展示它。 如果我使用 presentModalViewController 会发生两件(不需要的)事情 1) View 覆盖整个屏幕(除了状态栏)。 2)它是半透明的,但我在它“后面”看到的不是父 View ,而是应用程序 Root View 。
我尝试将其添加为 subview ,但没有任何反应,所以我没有做正确的事情:
RestaurantContextVC* modalViewController = [[[RestaurantContextVC alloc] initWithNibName:@"RestaurantContextView" bundle:nil] autorelease];
[self.view addSubview:modalViewController.view];
可以做我想做的事吗? 提前致谢。
贡索
最佳答案
我正在编写类似的代码。我的方法包括......
不使用dismissModalViewControllerAnimated和presentModalViewController:animated。
在 IB 中设计自定义的全尺寸 View 。在其viewDidLoad消息体中,将背景颜色设置为clearColor,以便 View 上未被 Controller 覆盖的空间是透明的。
我在 float View 的 Controller 下放置了一个 UIImageView。 UIImageView 包含一个经过 Photoshop 处理的图像,该图像具有圆角且背景设置为透明。该 ImageView 用作容器。
我使用 CoreAnimation 来呈现/关闭模态视图样式中的 float View :(FloatingViewController.m)
- (void)viewDidLoad { [super viewDidLoad]; [self.view setBackgroundColor:[UIColor clearColor]]; [UIView beginAnimations:nil context:nil]; [self.view setFrame:CGRectMake(0, 480, 320, 480)]; [UIView setAnimationDuration:0.75f]; [self.view setFrame:CGRectMake(0, 0, 320, 480)]; [UIView commitAnimations]; }
关于iPhone 模态视图比屏幕小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/915318/