5

我有两个 UIViewController,我在 firstViewController 上模态显示 secondViewController。我的 secondViewController 包含一个子视图,它是带有一些按钮的 UIView。现在我想做的是,使 SecondViewController 半透明,这样我的 firstViewController 是可见的,并且只显示不透明的子视图。

问候兰吉特

4

2 回答 2

4

当您展示您的视图控制器时,前一个控制器的视图将被删除,因此如果您为当前控制器的视图设置任何 alpha,您将获得 UIWindow 的背景。

如果您打算玩透明度,那么不要presentModalViewController在第一个视图控制器中执行 ,[self.view addSubView:controller2.view]; and make controller2.view.alpha = 0.5;//whatever transparency level u want

于 2012-07-19T12:45:59.237 回答
0

如果您的目标是 iOS 5.0 及更高版本,则可以使用容器视图控制器方法:

// create the modal view controller
MyModalController *modal = [[MyModalController alloc] 
  initWithNibName:@"MyModal" bundle:nil];
[modal willMoveToParentViewController:self];

// add it to the controllers and views hierarchies
[self addChildViewController:modal];
modal.view.frame = self.view.bounds;
[self.view addSubview:modal.view];
[modal didMoveToParentViewController:self];

然后,您在 IB 或代码中为主视图的背景设置的任何 alpha 都将受到尊重。

于 2012-11-01T22:57:06.997 回答